[Pip] : keep video aspect ratio for pip
This commit is contained in:
parent
95353ca673
commit
8c5fdb14a2
@ -451,15 +451,21 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public void enterPipMode() {
|
||||
Rational rational = new Rational(239, 100);
|
||||
Log.v(TAG, rational.toString());
|
||||
PictureInPictureParams mParams =
|
||||
new PictureInPictureParams.Builder()
|
||||
.setAspectRatio(rational)
|
||||
// .setSourceRectHint(new Rect(0,500,400,600))
|
||||
.build();
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById( R.id.video_player_fragment );
|
||||
|
||||
enterPictureInPictureMode(mParams);
|
||||
if ( videoPlayerFragment.getVideoAspectRatio() == 0 ) {
|
||||
Log.i( TAG, "impossible to switch to pip" );
|
||||
} else {
|
||||
Rational rational = new Rational( (int) ( videoPlayerFragment.getVideoAspectRatio() * 100 ), 100 );
|
||||
PictureInPictureParams mParams =
|
||||
new PictureInPictureParams.Builder()
|
||||
.setAspectRatio( rational )
|
||||
// .setSourceRectHint(new Rect(0,500,400,600))
|
||||
.build();
|
||||
|
||||
enterPictureInPictureMode( mParams );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,6 +86,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
private VideoPlayerService mService;
|
||||
private TorrentStream torrentStream;
|
||||
private LinearLayout torrentStatus;
|
||||
private float aspectRatio;
|
||||
|
||||
private static final String TAG = "VideoPlayerFragment";
|
||||
private GestureDetector mDetector;
|
||||
@ -112,6 +113,14 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
mBound = false;
|
||||
}
|
||||
};
|
||||
private AspectRatioFrameLayout.AspectRatioListener aspectRatioListerner = new AspectRatioFrameLayout.AspectRatioListener()
|
||||
{
|
||||
@Override
|
||||
public void onAspectRatioUpdated( float targetAspectRatio, float naturalAspectRatio, boolean aspectRatioMismatch )
|
||||
{
|
||||
aspectRatio = targetAspectRatio;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
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());
|
||||
simpleExoPlayerView.setOnTouchListener(touchListener);
|
||||
|
||||
simpleExoPlayerView.setAspectRatioListener( aspectRatioListerner );
|
||||
|
||||
torrentStatus = activity.findViewById(R.id.exo_torrent_status);
|
||||
|
||||
// Full screen Icon
|
||||
@ -278,6 +289,8 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
||||
}
|
||||
}
|
||||
|
||||
public float getVideoAspectRatio() { return aspectRatio; }
|
||||
|
||||
public boolean isPaused() {
|
||||
return !mService.player.getPlayWhenReady();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user