[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)
|
@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 );
|
||||||
PictureInPictureParams mParams =
|
|
||||||
new PictureInPictureParams.Builder()
|
|
||||||
.setAspectRatio(rational)
|
|
||||||
// .setSourceRectHint(new Rect(0,500,400,600))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user