androidx / androidx/media

Internal calls to the player crash apps that use a non-main applicationLooper

Open
#2,884 2 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Nov 11, 2025.

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

Description

Version

Media3 1.8.0

More version details

No response

Devices that reproduce the issue

I can reproduce this on any device.

Devices that do not reproduce the issue

None.

Reproducible in the demo app?

Not tested

Reproduction steps
  1. Configure the player to use a non-main thread (i.e., call setLooper(playerThread.looper))
  2. Ensure onTaskRemoved() implementation is not overridden (or super is called if it is)
  3. Play media
  4. Remove the playing app from recents
Expected result

Internal calls to the player should use the correct thread, and playback should continue after the task is removed.

Actual result

Internal calls to the player use the main/wrong thread, app crashes, and playback stops.

Stack trace:

Exception java.lang.RuntimeException:
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5503)
  at android.app.ActivityThread.-$$Nest$mhandleServiceArgs (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2716)
  at android.os.Handler.dispatchMessage (Handler.java:114)
  at android.os.Looper.loopOnce (Looper.java:206)
  at android.os.Looper.loop (Looper.java:296)
  at android.app.ActivityThread.main (ActivityThread.java:9205)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:591)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1027)
Caused by java.lang.IllegalStateException: Player is accessed on the wrong thread.
Current thread: 'main'
Expected thread: 'PlayerThread'
See https://developer.android.com/guide/topics/media/issues/player-accessed-on-wrong-thread
  at androidx.media3.exoplayer.ExoPlayerImpl.verifyApplicationThread (ExoPlayerImpl.java:2920)
  at androidx.media3.exoplayer.ExoPlayerImpl.setPlayWhenReady (ExoPlayerImpl.java)
  at androidx.media3.common.ForwardingPlayer.setPlayWhenReady (ForwardingPlayer.java:262)
  at androidx.media3.session.MediaSessionService.pauseAllPlayersAndStopSelf (MediaSessionService.java:579)
  at androidx.media3.session.MediaSessionService.onTaskRemoved (MediaSessionService.java:617)
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5485)

Even if onTaskRemoved() is overridden to call the super implementation on the proper player thread (hacky), the app still crashes, but only in the paused state:

Exception java.lang.IllegalStateException: MediaController method is called from a wrong thread. See javadoc of MediaController for details.
  at androidx.media3.common.util.Assertions.checkState (Assertions.java:100)
  at androidx.media3.session.MediaController.verifyApplicationThread (MediaController.java:2113)
  at androidx.media3.session.MediaController.getPlayWhenReady (MediaController.java)
  at androidx.media3.session.MediaNotificationManager.isAnySessionUserEngaged (MediaNotificationManager.java:246)
  at androidx.media3.session.MediaNotificationManager.shouldRunInForeground (MediaNotificationManager.java:229)
  at androidx.media3.session.MediaSessionService.onUpdateNotificationInternal (MediaSessionService.java:711)
  at androidx.media3.session.MediaNotificationManager.disableUserEngagedTimeout (MediaNotificationManager.java:265)
  at androidx.media3.session.MediaSessionService.pauseAllPlayersAndStopSelf (MediaSessionService.java:576)
  at androidx.media3.session.MediaSessionService.onTaskRemoved (MediaSessionService.java:617)
  at org.fossify.musicplayer.playback.PlaybackService.onTaskRemoved$lambda$0 (PlaybackService.kt)  (here call was posted using player looper)
  at android.os.Handler.handleCallback (Handler.java:978)
  at android.os.Handler.dispatchMessage (Handler.java:104)
  at android.os.Looper.loopOnce (Looper.java:238)
  at android.os.Looper.loop (Looper.java:357)
  at android.os.HandlerThread.run (HandlerThread.java:67)
Media

Any audio file will work fine.

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

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.