While I play a content with a different url while PiP mode is on, the old content is playing.
I made all the suggested adjustments in the file AndroidManifest.xml
<activity
android:name=".presentation.ui.player.live.LivePlayerActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:excludeFromRecents="false"
android:launchMode="singleTask"
android:noHistory="true"
android:parentActivityName=".presentation.ui.main.MainActivity"
android:resizeableActivity="true"
android:screenOrientation="landscape"
android:supportsPictureInPicture="true"
android:taskAffinity=""
android:windowSoftInputMode="adjustPan"
tools:targetApi="n" />
<activity
The same content plays even though I click on a different element in the RecyclerView
. It does not work correctly when PiP mode is running.
private val onChannelSelectedListener = object : ChannelAdapter.OnChannelSelectedListener {
override fun onChannelSelected(channel: Channel) {
activity?.let { startActivity(LivePlayerActivity.newIntent(it, channelId = channel.id)) }
}
}
In this class, many features have been added for PiP mode operation. It works flawlessly.
BasePlayerActivity.kt
@RequiresApi(Build.VERSION_CODES.O)
private fun playPipMode() {
pictureInPicturePlayContent(true)
updatePictureInPictureActions(
R.drawable.ic_player_pause,
"",
CONTROL_TYPE_PAUSE,
REQUEST_PAUSE
)
}
@RequiresApi(Build.VERSION_CODES.O)
private fun pausePipMode() {
pictureInPicturePlayContent(false)
updatePictureInPictureActions(
R.drawable.ic_player_play,
"",
CONTROL_TYPE_PLAY,
REQUEST_PLAY
)
}
fun enterPictureInPicture(isUserAction: Boolean = false) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (pictureInPictureParamsBuilder == null) {
pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
}
pictureInPictureParamsBuilder?.apply {
setAspectRatio(Rational(16, 9))
updatePictureInPictureActions(
R.drawable.ic_player_pause,
"",
CONTROL_TYPE_PAUSE,
REQUEST_PAUSE
)
}?.let {
enterPictureInPictureMode(it.build())
}
}
if (isUserAction) {
navToLauncherTask()
}
}
@RequiresApi(Build.VERSION_CODES.O)
fun updatePictureInPictureActions(
@DrawableRes iconId: Int,
title: String,
controlType: Int,
requestCode: Int
) {
val actions = arrayListOf<RemoteAction>()
val pendingIntentFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
val intent = PendingIntent.getBroadcast(
this,
requestCode,
Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
pendingIntentFlag
)
val icon = Icon.createWithResource(this, iconId)
actions.add(RemoteAction(icon, title, title, intent))
pictureInPictureParamsBuilder?.apply {
setActions(actions)
}?.let {
setPictureInPictureParams(it.build())
}
}
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (isInPictureInPictureMode) { // Starts receiving events from action items in PiP mode.
registerPipModeReceivers()
} else if (!this.isInPictureInPictureMode) {
errorPopupRunnable?.run()
errorPopupRunnable = null
cancelAudioMode(isOnStop)
unRegisterPipModeReceivers()
}
}
}
@RequiresApi(Build.VERSION_CODES.O)
private fun registerPipModeReceivers() {
registerReceiver(pictureInPictureActionReceiver, IntentFilter(ACTION_MEDIA_CONTROL))
if (pipModeAudioFocus == null) {
pipModeAudioFocus = getPipModeAudioFocus()
}
pipModeAudioFocus?.let { audioManager.requestAudioFocus(it) }
}
private fun unRegisterPipModeReceivers() {
try {
unregisterReceiver(pictureInPictureActionReceiver)
} catch (e: IllegalArgumentException) {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
pipModeAudioFocus?.let { audioManager.abandonAudioFocusRequest(it) }
}
}
What should I do?