fix(pip): handle two autoPip views

This commit is contained in:
2026-08-04 09:47:10 +02:00
parent 9945f2b339
commit 9fea0949bd
3 changed files with 13 additions and 14 deletions
@@ -227,13 +227,15 @@ class OmniPlayer(
.build()
}
fun setVideoView(surfaceView: android.view.SurfaceView?) {
fun setVideoView(surfaceView: android.view.SurfaceView) {
runOnMainThread {
if (surfaceView == null) {
localPlayer.clearVideoSurface()
} else {
localPlayer.setVideoSurfaceView(surfaceView)
}
localPlayer.setVideoSurfaceView(surfaceView)
}
}
fun clearVideoView(surfaceView: android.view.SurfaceView) {
runOnMainThread {
localPlayer.clearVideoSurfaceView(surfaceView)
}
}
@@ -154,15 +154,11 @@ class OmniView(val context: ThemedReactContext) :
val curPip = activeView.get()
when {
autoPip == true && curPip == this -> {}
autoPip == true && curPip == null -> {
autoPip == true -> {
activeView = WeakReference(this)
updatePictureInPictureParams()
}
autoPip == true -> {
throw Error("Only one OmniView can have `autoPip` set at a time.")
}
autoPip == false && curPip == this -> {
activeView = WeakReference(null)
clearPictureInPictureParams()
@@ -180,7 +176,7 @@ class OmniView(val context: ThemedReactContext) :
}
boundPlayer?.localPlayer?.removeListener(this)
boundPlayer?.setVideoView(null)
boundPlayer?.clearVideoView(surfaceView)
boundPlayer = omniPlayer
omniPlayer.localPlayer.addListener(this)
@@ -206,7 +202,7 @@ class OmniView(val context: ThemedReactContext) :
val omniPlayer = player as? OmniPlayer ?: return
boundPlayer?.localPlayer?.removeListener(this)
omniPlayer.setVideoView(null)
omniPlayer.clearVideoView(surfaceView)
boundPlayer = null
}
@@ -414,6 +410,6 @@ class OmniView(val context: ThemedReactContext) :
override fun surfaceDestroyed(holder: SurfaceHolder) {
surfaceReady = false
surfaceView.removeCallbacks(rebuildRunnable)
boundPlayer?.setVideoView(null)
boundPlayer?.clearVideoView(surfaceView)
}
}
@@ -894,6 +894,7 @@ class VlcPlayer(ctx: Context) :
}
override fun clearVideoSurfaceView(surfaceView: SurfaceView?) {
if (surfaceView != null && boundSurfaceView !== surfaceView) return
clearVideoSurface()
}