androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.54k stars 373 forks source link

Performing pause of activity that is not resumed When enter PictureInPicture model #785

Closed liuchuancong closed 1 month ago

liuchuancong commented 10 months ago

Version

Media3 1.1.1

More version details

main

Devices that reproduce the issue

xiao mi mix4 android 13

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

1 play video 2 toggle pip

Expected result

not log

Actual result

java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.mystyle.purelive/com.mystyle.purelive.MainActivity} E/ActivityThread(29777): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:5201) E/ActivityThread(29777): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:5166) E/ActivityThread(29777): at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:47) E/ActivityThread(29777): at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) E/ActivityThread(29777): at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) E/ActivityThread(29777): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) E/ActivityThread(29777): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2389) E/ActivityThread(29777): at android.os.Handler.dispatchMessage(Handler.java:106) E/ActivityThread(29777): at android.os.Looper.loopOnce(Looper.java:210) E/ActivityThread(29777): at android.os.Looper.loop(Looper.java:299) E/ActivityThread(29777): at android.app.ActivityThread.main(ActivityThread.java:8261) E/ActivityThread(29777): at java.lang.reflect.Method.invoke(Native Method) E/ActivityThread(29777): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559) E/ActivityThread(29777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)

Media

private fun enablePictureInPicture(player: BetterPlayer) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            player.setupMediaSession(flutterState!!.applicationContext)
            activity!!.enterPictureInPictureMode(PictureInPictureParams.Builder().build())
            startPictureInPictureListenerTimer(player)
            player.onPictureInPictureStatusChanged(true)
        }
    }
private fun startPictureInPictureListenerTimer(player: BetterPlayer) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            pipHandler = Handler(Looper.getMainLooper())
            pipRunnable = Runnable {
                if (activity!!.isInPictureInPictureMode) {
                    pipHandler!!.postDelayed(pipRunnable!!, 100)
                } else {
                    player.onPictureInPictureStatusChanged(false)
                    player.disposeMediaSession()
                    stopPipHandler()
                }
            }
            pipHandler!!.post(pipRunnable!!)
        }
    }

Not work!

Bug Report

marcbaechinger commented 10 months ago

Thanks for your report.

I doubt this has something to do with Media3 I'm afraid. I can't give you a better answer than pointing to the documentation that you probably already know: https://developer.android.com/develop/ui/views/picture-in-picture

The stack trace does not contain a trace of a Media3 class being involved. The error message points in the direction of that PIP is requested for an activity that is not in the foreground (Performing pause of activity that is not resumed). That's where I would start investigating the issue which seems related to problems with the activity lifecycle.

I leave this issue open for a while in case someone else can help you with this and give you a hint what the problem is.

If you think this is indeed an issue with Media3, please narrow down your report to indicate what the library is doing wrong in such a case.

liuchuancong commented 9 months ago

@marcbaechinger Thank you for your answer.It's a flutter plugin. Not android project.This problem may be caused by flutter.This error does not affect the use of.

MohdSaadi commented 1 month ago

@liuchuancong any updates ?