I am creating a media player application and I would like to support picture in picture. My problem is whenever I enter PIP, the player activity separates itself from the previous activity and such.
Here is my activity declaration:
<activity
android:name=".ui.player.PlayerActivity"
android:allowTaskReparenting="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/player"
android:launchMode="singleTask"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsPictureInPicture="true">
Here is the code that I use to enter PIP:
override fun onUserLeaveHint() {
enterPictureInPicture()
}
private fun enterPictureInPicture() {
val player = manager.currentPlayer
if (player is SimpleExoPlayer) {
val format = player.videoFormat
val params = PictureInPictureParams.Builder()
.setAspectRatio(format?.let { Rational(it.width, it.height) } ?: Rational(16, 9))
.build()
enterPictureInPictureMode(params)
}
}