-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: Getting crash issues in Android v<=11 due to PIP mode #4436
Comments
Previous bot comment (click to expand)Thank you for your bug report. We will review it and get back to you if we need more information. |
Previous bot comment (click to expand)Thank you for your bug report. We will review it and get back to you if we need more information. |
@freeboub Please look into it, it's a major crash issue |
Previous bot comment (click to expand)Thank you for your bug report. We will review it and get back to you if we need more information. |
Thank you for your bug report. We will review it and get back to you if we need more information. |
@freeboub Please update these functions: @JvmStatic
fun enterPictureInPictureMode(context: ThemedReactContext, pictureInPictureParams: PictureInPictureParams?) {
if (!isSupportPictureInPicture(context)) return
if (isSupportPictureInPictureAction() && pictureInPictureParams != null) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
pictureInPictureParams.aspectRatio?.let {
val ratio = it.toFloat()
if (ratio < 0.418410 || ratio > 2.39) {
DebugLog.e(TAG, "Aspect ratio out of range: $ratio. Skipping PiP mode.")
return
}
}
}
context.findActivity().enterPictureInPictureMode(pictureInPictureParams)
} catch (e: IllegalStateException) {
DebugLog.e(TAG, e.toString())
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
@Suppress("DEPRECATION")
context.findActivity().enterPictureInPictureMode()
} catch (e: IllegalStateException) {
DebugLog.e(TAG, e.toString())
}
}
}
@JvmStatic
@RequiresApi(Build.VERSION_CODES.O)
fun calcPictureInPictureAspectRatio(player: ExoPlayer): Rational {
if (player.videoSize.width == 0 || player.videoSize.height == 0) {
return Rational(16, 9)
}
var aspectRatio = Rational(player.videoSize.width, player.videoSize.height)
// AspectRatio for the activity in picture-in-picture, must be between 2.39:1 and 1:2.39 (inclusive).
// https://developer.android.com/reference/android/app/PictureInPictureParams.Builder#setAspectRatio(android.util.Rational)
val maximumRatio = Rational(239, 100)
val minimumRatio = Rational(100, 239)
if (aspectRatio.toFloat() > maximumRatio.toFloat()) {
aspectRatio = maximumRatio
} else if (aspectRatio.toFloat() < minimumRatio.toFloat()) {
aspectRatio = minimumRatio
}
return aspectRatio
} as I'm not able to create the patch of this package so please fix the issue |
@MdAbubakar Thank you for the patch, can you please open a pull request with the necessary change ? |
@freeboub Thank you for your response, Sure I'll create the pull request but please look into all the mentioned crash issues. |
I open the PR here: #4438 |
Judging from the error log, the problem is that calcPictureInPictureAspectRatio is called when player is null. I'm not sure if this PR fixes that.🤔
Unfortunately, I don't have any real Android 11 device, so it would be helpful if you could let me know what you get for the ratio.
Do you have an app that uses multiple activities rather than multiple single activity apps? current code assumes a single activity app.
This is a known issue that can occur when multiple players are present at the same time. We haven't fixed this yet, and it's not a simple fix because react-native-video has a lot of features. |
@YangJonghun this is my request to you please check the PR: #4440 if my changes affecting other features then don't approve it but I have checked in real devices in Android 10, 11, 12, 13 and 14 after making the changes in PR: #4440 and in all versions of android all the other features are working and the PIP mode also working and now I'm not getting any crash. Earlier I was getting crash in all android versions while playing the content and making the app to background the app was crashing after applying the changes the PIP mode is working everytime without any crash please check the PR: #4440 once Thanks in advance! |
Version
6.10.2
What platforms are you having the problem on?
Android
System Version
Android <= 11
On what device are you experiencing the issue?
Real device
Architecture
Old architecture
What happened?
Getting multiple crashes on Android devices below version 12 means android 11 and below the crash is due to PIP mode. Please check the crash traces:
Fatal Exception: java.lang.NullPointerException
Parameter specified as non-null is null: method com.brentvatne.exoplayer.PictureInPictureUtil.calcPictureInPictureAspectRatio, parameter player
com.brentvatne.exoplayer.PictureInPictureUtil.calcPictureInPictureAspectRatio (PictureInPictureUtil.kt:3)
com.brentvatne.exoplayer.ReactExoplayerView.enterPictureInPictureMode (ReactExoplayerView.java:2298)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onUserLeaveHintCallback$1.invoke (PictureInPictureUtil.kt:53)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onUserLeaveHintCallback$1.invoke (PictureInPictureUtil.kt:51)
com.brentvatne.exoplayer.PictureInPictureUtil.addLifecycleEventListener$lambda$0 (PictureInPictureUtil.kt:60)
androidx.activity.ComponentActivity.onUserLeaveHint (ComponentActivity.kt:1037)
com.facebook.react.ReactActivity.onUserLeaveHint (ReactActivity.java:118)
android.app.Activity.performUserLeaving (Activity.java:8412)
android.app.Instrumentation.callActivityOnUserLeaving (Instrumentation.java:1520)
android.app.ActivityThread.performUserLeavingActivity (ActivityThread.java:5161)
android.app.ActivityThread.handlePauseActivity (ActivityThread.java:5145)
android.app.servertransaction.PauseActivityItem.execute (PauseActivityItem.java:46)
android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:176)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2317)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:246)
android.app.ActivityThread.main (ActivityThread.java:8595)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
Another crash due to PIP mode is:
Fatal Exception: java.lang.IllegalArgumentException
enterPictureInPictureMode: Aspect ratio is too extreme (must be between 0.418410 and 2.390000).
android.os.Parcel.createException (Parcel.java:2091)
android.app.Activity.enterPictureInPictureMode (Activity.java:2786)
com.brentvatne.exoplayer.PictureInPictureUtil.enterPictureInPictureMode (PictureInPictureUtil.kt:77)
com.brentvatne.exoplayer.ReactExoplayerView.enterPictureInPictureMode (ReactExoplayerView.java:2301)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onUserLeaveHintCallback$1.invoke (PictureInPictureUtil.kt:53)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onUserLeaveHintCallback$1.invoke (PictureInPictureUtil.kt:51)
com.brentvatne.exoplayer.PictureInPictureUtil.addLifecycleEventListener$lambda$0 (PictureInPictureUtil.kt:60)
androidx.activity.ComponentActivity.onUserLeaveHint (ComponentActivity.kt:1037)
com.facebook.react.ReactActivity.onUserLeaveHint (ReactActivity.java:118)
android.app.Activity.performUserLeaving (Activity.java:8185)
android.app.Instrumentation.callActivityOnUserLeaving (Instrumentation.java:1518)
android.app.ActivityThread.performUserLeavingActivity (ActivityThread.java:4725)
android.app.ActivityThread.handlePauseActivity (ActivityThread.java:4710)
android.app.servertransaction.PauseActivityItem.execute (PauseActivityItem.java:46)
android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:181)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:102)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2232)
android.os.Handler.dispatchMessage (Handler.java:107)
android.os.Looper.loop (Looper.java:238)
android.app.ActivityThread.main (ActivityThread.java:7824)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:981)
Caused by android.os.RemoteException
Remote stack trace: at com.android.server.wm.ActivityTaskManagerService.ensureValidPictureInPictureActivityParamsLocked(ActivityTaskManagerService.java:4487) at com.android.server.wm.ActivityTaskManagerService.enterPictureInPictureMode(ActivityTaskManagerService.java:4347) at android.app.IActivityTaskManager$Stub.onTransact(IActivityTaskManager.java:3274) at com.android.server.wm.OppoActivityTaskManagerService.onTransact(OppoActivityTaskManagerService.java:110) at android.os.Binder.execTransactInternal(Binder.java:1021)
Another crash due to PIP mode is:
Fatal Exception: java.lang.IndexOutOfBoundsException
Index 1 out of bounds for length 1
jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:64)
jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
jdk.internal.util.Preconditions.checkIndex (Preconditions.java:266)
java.util.Objects.checkIndex (Objects.java:359)
java.util.ArrayList.get (ArrayList.java:434)
com.brentvatne.exoplayer.ReactExoplayerView.setIsInPictureInPicture (ReactExoplayerView.java:2285)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onPictureInPictureModeChanged$1.invoke (PictureInPictureUtil.kt:44)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onPictureInPictureModeChanged$1.invoke (PictureInPictureUtil.kt:43)
com.brentvatne.exoplayer.PictureInPictureUtilKt$sam$androidx_core_util_Consumer$0.accept (PictureInPictureUtil.kt:2)
androidx.activity.ComponentActivity.onPictureInPictureModeChanged (ComponentActivity.kt:1008)
android.app.Activity.dispatchPictureInPictureModeChanged (Activity.java:9039)
android.app.ActivityThread.handleWindowingModeChangeIfNeeded (ActivityThread.java:6432)
android.app.ActivityThread.performActivityConfigurationChanged (ActivityThread.java:6271)
android.app.ActivityThread.performConfigurationChangedForActivity (ActivityThread.java:6248)
android.app.ActivityThread.handleActivityConfigurationChanged (ActivityThread.java:6592)
android.app.servertransaction.ActivityConfigurationChangeItem.execute (ActivityConfigurationChangeItem.java:53)
android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2532)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loopOnce (Looper.java:223)
android.os.Looper.loop (Looper.java:324)
android.app.ActivityThread.main (ActivityThread.java:8504)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:582)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1061)
Another crash:
Fatal Exception: java.lang.IllegalStateException
The specified child already has a parent. You must call removeView() on the child's parent first.
android.view.ViewGroup.addViewInner (ViewGroup.java:5362)
android.view.ViewGroup.addView (ViewGroup.java:5176)
com.brentvatne.exoplayer.ReactExoplayerView.setIsInPictureInPicture (ReactExoplayerView.java:2287)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onPictureInPictureModeChanged$1.invoke (PictureInPictureUtil.kt:44)
com.brentvatne.exoplayer.PictureInPictureUtil$addLifecycleEventListener$onPictureInPictureModeChanged$1.invoke (PictureInPictureUtil.kt:43)
com.brentvatne.exoplayer.PictureInPictureUtilKt$sam$androidx_core_util_Consumer$0.accept (PictureInPictureUtil.kt:2)
androidx.activity.ComponentActivity.onPictureInPictureModeChanged (ComponentActivity.kt:1008)
android.app.Activity.dispatchPictureInPictureModeChanged (Activity.java:9749)
android.app.ActivityThread.handleWindowingModeChangeIfNeeded (ActivityThread.java:7494)
android.app.ActivityThread.performActivityConfigurationChanged (ActivityThread.java:7181)
android.app.ActivityThread.performConfigurationChangedForActivity (ActivityThread.java:7156)
android.app.ActivityThread.handleActivityConfigurationChangedInner (ActivityThread.java:7760)
android.app.ActivityThread.handleActivityConfigurationChanged (ActivityThread.java:7679)
android.app.ActivityThread.handleActivityConfigurationChanged (ActivityThread.java:7651)
android.app.servertransaction.ActivityConfigurationChangeItem.execute (ActivityConfigurationChangeItem.java:57)
android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:60)
android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem (TransactionExecutor.java:220)
android.app.servertransaction.TransactionExecutor.executeTransactionItems (TransactionExecutor.java:148)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:120)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:3079)
android.os.Handler.dispatchMessage (Handler.java:109)
android.os.Looper.loopOnce (Looper.java:250)
android.os.Looper.loop (Looper.java:340)
android.app.ActivityThread.main (ActivityThread.java:9860)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:621)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)
Reproduction Link
no repository link
Reproduction
Step to reproduce this bug are:
you can reproduce the issue in Android 11 or below
The text was updated successfully, but these errors were encountered: