Google's Leanback showcase video player without ExoPlayer
Google's Leanback showcase video player with ExoPlayer
I've tried out the leanback showcase from google and it too plays the videos on "fit to screen" mode with black bars on the sides. I can't find an option to change the scale mode anywhere on the API docs either
I had to look into the VideoFragment
source to figure this one out. VideoFragment
has a simple SurfaceView
as the root element of its layout and all you have to do is make the SurfaceView
match the parent (which is the device screen) width and height. To do that just override onVideoSizeChanged
and use getSurfaceView
to get a reference to the package-private SurfaceView
instance used in the VideoFragment
.
@Override
protected void onVideoSizeChanged(int width, int height) {
switch (scaleMode) {
// `scaleMode` flag indicates that this video should stretch to screen
case MediaMetaData.SCALE_MODE_STRETCH:
View rootView = getView();
SurfaceView surfaceView = getSurfaceView();
ViewGroup.LayoutParams params = surfaceView.getLayoutParams();
params.height = rootView.getHeight();
params.width = rootView.getWidth();
surfaceView.setLayoutParams(params);
break;
// When the video shouldn't stretch, just invoke super to have the VideoFragment's default behavior which is fit to screen
default:
super.onVideoSizeChanged(width, height);
}
}