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?
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.
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!
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With