Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android, using exoplayer, how to fill surfaceview with a video that does not have the same aspect ratio with the device?

I have an activity that uses ExoPlayer to play a video. When I go fullscreen, unless the aspect ratio of the device is equal to that of the video, I get small black bars at the top and the bottom of the video.

This is how the layout looks :

<com.google.android.exoplayer.AspectRatioFrameLayout
    android:id="@+id/video_frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true">

    <SurfaceView android:id="@+id/surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"/>

    <View android:id="@+id/shutter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"/>

</com.google.android.exoplayer.AspectRatioFrameLayout>

I was hoping that

aspectRatioFrameLayout.setAspectRatio(mVideo.getAspectRatio());

would solve the problem, but I had no success. Is there a way to fill the screen with the video, even if part of the video is cut off from the screen?

like image 352
kimv Avatar asked Nov 09 '15 12:11

kimv


People also ask

How do I change video quality on ExoPlayer?

ExoPlayer provides a way of setting a max bitrate using DefaultTrackSelector#Parameters . You can use setMaxVideoBitrate or setMaxVideoSize to limit the max bitrate. In this way, it works in many cases.

Can we play YouTube video in ExoPlayer Android?

ExoPlayer is the video player running in Android YouTube, Netflix, Amazon media player for Prime, HotStar, and many other popular and robust apps. Good documentation and tutorials. It's free!

Does ExoPlayer use mediaplayer?

ExoPlayer is an app-level media player built on top of low-level media APIs in Android. It is an open source project used by Google apps, including YouTube and Google TV.


1 Answers

There is a fastest way to fill the screen with the video. Go to the SimpleExoPlayerView.java class, change the resizeMode from AspectRatioFrameLayout.RESIZE_MODE_FIT to AspectRatioFrameLayout.RESIZE_MODE_FILL. RESIZE_MODE_FILL will ignore the specified aspect ratio. Use this way if you use ExoPlayer as a module in your project.

UPDATED If you use ExoPlayer as a library, they have a method to setResizeMode(). You just set to AspectRatioFrameLayout.RESIZE_MODE_FILL in your view: simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL) That's all!

like image 165
Hien Quang Le Avatar answered Sep 17 '22 12:09

Hien Quang Le