[Pip] : keep video aspect ratio for pip

This commit is contained in:
Olivier Bouillet 2020-09-24 22:38:02 +02:00
parent 95353ca673
commit 8c5fdb14a2
2 changed files with 27 additions and 8 deletions

View File

@ -451,8 +451,13 @@ public class VideoPlayActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public void enterPipMode() { public void enterPipMode() {
Rational rational = new Rational(239, 100); final FragmentManager fragmentManager = getSupportFragmentManager();
Log.v(TAG, rational.toString()); final VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById( R.id.video_player_fragment );
if ( videoPlayerFragment.getVideoAspectRatio() == 0 ) {
Log.i( TAG, "impossible to switch to pip" );
} else {
Rational rational = new Rational( (int) ( videoPlayerFragment.getVideoAspectRatio() * 100 ), 100 );
PictureInPictureParams mParams = PictureInPictureParams mParams =
new PictureInPictureParams.Builder() new PictureInPictureParams.Builder()
.setAspectRatio( rational ) .setAspectRatio( rational )
@ -461,6 +466,7 @@ public class VideoPlayActivity extends AppCompatActivity {
enterPictureInPictureMode( mParams ); enterPictureInPictureMode( mParams );
} }
}
@Override @Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {

View File

@ -86,6 +86,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
private VideoPlayerService mService; private VideoPlayerService mService;
private TorrentStream torrentStream; private TorrentStream torrentStream;
private LinearLayout torrentStatus; private LinearLayout torrentStatus;
private float aspectRatio;
private static final String TAG = "VideoPlayerFragment"; private static final String TAG = "VideoPlayerFragment";
private GestureDetector mDetector; private GestureDetector mDetector;
@ -112,6 +113,14 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
mBound = false; mBound = false;
} }
}; };
private AspectRatioFrameLayout.AspectRatioListener aspectRatioListerner = new AspectRatioFrameLayout.AspectRatioListener()
{
@Override
public void onAspectRatioUpdated( float targetAspectRatio, float naturalAspectRatio, boolean aspectRatioMismatch )
{
aspectRatio = targetAspectRatio;
}
};
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
@ -144,6 +153,8 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
mDetector = new GestureDetector(context, new MyGestureListener()); mDetector = new GestureDetector(context, new MyGestureListener());
simpleExoPlayerView.setOnTouchListener(touchListener); simpleExoPlayerView.setOnTouchListener(touchListener);
simpleExoPlayerView.setAspectRatioListener( aspectRatioListerner );
torrentStatus = activity.findViewById(R.id.exo_torrent_status); torrentStatus = activity.findViewById(R.id.exo_torrent_status);
// Full screen Icon // Full screen Icon
@ -278,6 +289,8 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
} }
} }
public float getVideoAspectRatio() { return aspectRatio; }
public boolean isPaused() { public boolean isPaused() {
return !mService.player.getPlayWhenReady(); return !mService.player.getPlayWhenReady();
} }