androidx / androidx/media

Media resumption results in DeadObjectException

Open
#1,557 3 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jul 22, 2024.

bug needs triage
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

1.4.0-rc01

Devices that reproduce the issue

Android Studio emulator: Pixel 8 Pro API 34 - Android 14
Asus zenfone 9 Android 14

Devices that do not reproduce the issue

Pixel 7 Android 14

Reproducible in the demo app?

No

Reproduction steps

I am trying to fix a bug for MediaResumption that occurs on some devices.
My problem occurs in the following scenario :

  1. Play something
  2. Pause it
  3. Swipe app away from recents.
  4. See a dead/stale notification that does not trigger onPlaybackResumption

Steps to reproduce
With UAMP (media3 branch) i am able to reproduce the issue by doing the following:

1 . Use the latest Media3 version 1.4.0-rc01 because it contains pauseAllPlayersAndStopSelf().
2. In the MusicService.kt implement this:

    override fun onTaskRemoved(rootIntent: Intent?) {
        super.onTaskRemoved(rootIntent)
        Log.d("[DEBUG]", "onTaskRemoved: ")
        pauseAllPlayersAndStopSelf()
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("[DEBUG]", "onDestroy: ")
    }

3 . Add this to the MusicServiceCallback in the MediaService

        override fun onPlaybackResumption(
            mediaSession: MediaSession,
            controller: MediaSession.ControllerInfo
        ): ListenableFuture<MediaSession.MediaItemsWithStartPosition> {
            Log.d("[DEBUG]", "onPlaybackResumption: <------------")
            return super.onPlaybackResumption(mediaSession, controller)
        }

By doing the above we cannot expect MediaResumption to work because onPlaybackResumption does nothing but printing a log. But it should get called.

  1. Run the app with Android Studio and
    1. Play something
    2. Pause it
    3. Swipe app away from recents.
    4. See a dead/stale notification that does not trigger onPlaybackResumption

  2. Open logcat and CLEAR all the filters and observe this exception

2024-07-19 12:02:05.434   524-852   MediaSessionRecord      system_server                        E  Remote failure in play.
                                                                                                    android.os.DeadObjectException
                                                                                                    	at android.os.BinderProxy.transactNative(Native Method)
                                                                                                    	at android.os.BinderProxy.transact(BinderProxy.java:584)
                                                                                                    	at android.media.session.ISessionCallback$Stub$Proxy.onPlay(ISessionCallback.java:729)
                                                                                                    	at com.android.server.media.MediaSessionRecord$SessionCb.play(MediaSessionRecord.java:1408)
                                                                                                    	at com.android.server.media.MediaSessionRecord$ControllerStub.play(MediaSessionRecord.java:1743)
                                                                                                    	at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:523)
                                                                                                    	at android.os.Binder.execTransactInternal(Binder.java:1344)
                                                                                                    	at android.os.Binder.execTransact(Binder.java:1275)
                                                                                                    	

The fact that pauseAllPlayersAndStopSelf got introduced helped me to address a bug that restarted my MediaService, which is nice. But also resulted in the above for some devices.

Expected result

onPlaybackResumption() should get called so we can load items to resume.

Actual result

Stale notification and an exception is thrown:

Remote failure in play.
                                                                                                    android.os.DeadObjectException
                                                                                                    	at android.os.BinderProxy.transactNative(Native Method)
                                                                                                    	at android.os.BinderProxy.transact(BinderProxy.java:584)
                                                                                                    	at android.media.session.ISessionCallback$Stub$Proxy.onPlay(ISessionCallback.java:729)
                                                                                                    	at com.android.server.media.MediaSessionRecord$SessionCb.play(MediaSessionRecord.java:1408)
                                                                                                    	at com.android.server.media.MediaSessionRecord$ControllerStub.play(MediaSessionRecord.java:1743)
                                                                                                    	at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:523)
                                                                                                    	at android.os.Binder.execTransactInternal(Binder.java:1344)
                                                                                                    	at android.os.Binder.execTransact(Binder.java:1275)

Note
Probably related to this

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.