Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

IllegalStateException about wrong thread Player access upon MediaSessionService connection #318

Copy link
Copy link
@bubenheimer

Description

@bubenheimer
Issue body actions

Media3 Version

Media3 1.0.0

Devices that reproduce the issue

Android emulator

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

I have a custom player class extending SimpleBasePlayer, using a non-main looper. It is part of a MediaSessionService that runs in a separate process from the client.

The service crashes, complaining about the looper, apparently when the client connects. I suspect this may be a bug in media3, I do not see any any of my own code in the stacktrace. I also do not see a way to influence the media3 behavior here, short of possibly implementing my own notification scheme, running the player on the main looper, or not offering a Timeline right away.

The only place on the service side where I specify the non-main looper is in the SimpleBasePlayer constructor. I have not seen another applicable API to customize the looper.

I assume the stacktrace will be sufficient to pinpoint the logic error here.

Expected result

No service crash when connecting to MediaSessionService.

Actual result

The MediaSessionService crashes:

RuntimeException while executing runnable androidx.media3.session.MediaNotificationManager$$ExternalSyntheticLambda1@6f7d357 with executor androidx.media3.session.MediaNotificationManager$$ExternalSyntheticLambda2@633ae44
java.lang.IllegalStateException: Player is accessed on the wrong thread.
Current thread: 'main'
Expected thread: 'OffMainLooper'
See https://exoplayer.dev/issues/player-accessed-on-wrong-thread
    at androidx.media3.common.SimpleBasePlayer.verifyApplicationThreadAndInitState(SimpleBasePlayer.java:3360)
    at androidx.media3.common.SimpleBasePlayer.getCurrentTimeline(SimpleBasePlayer.java:2415)
    at androidx.media3.session.MediaNotificationManager.shouldShowNotification(MediaNotificationManager.java:256)
    at androidx.media3.session.MediaNotificationManager.access$000(MediaNotificationManager.java:54)
    at androidx.media3.session.MediaNotificationManager$MediaControllerListener.onConnected(MediaNotificationManager.java:275)
    at androidx.media3.session.MediaNotificationManager.lambda$addSession$1$androidx-media3-session-MediaNotificationManager(MediaNotificationManager.java:103)
    at androidx.media3.session.MediaNotificationManager$$ExternalSyntheticLambda1.run(Unknown Source:8)
    at androidx.media3.common.util.Util.postOrRun(Util.java:607)
    at androidx.media3.session.MediaNotificationManager.lambda$new$0(MediaNotificationManager.java:80)
    at androidx.media3.session.MediaNotificationManager$$ExternalSyntheticLambda2.execute(Unknown Source:2)
    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1270)
    at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:1038)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:783)
    at androidx.media3.session.MediaControllerHolder.maybeSetFutureResult(MediaControllerHolder.java:62)
    at androidx.media3.session.MediaControllerHolder.onAccepted(MediaControllerHolder.java:52)
    at androidx.media3.session.MediaController.notifyAccepted(MediaController.java:1849)
    at androidx.media3.session.MediaControllerImplBase.onConnected(MediaControllerImplBase.java:2163)
    at androidx.media3.session.MediaControllerStub.lambda$onConnected$0(MediaControllerStub.java:87)
    at androidx.media3.session.MediaControllerStub$$ExternalSyntheticLambda6.run(Unknown Source:2)
    at androidx.media3.session.MediaControllerStub.lambda$dispatchControllerTaskOnHandler$11(MediaControllerStub.java:301)
    at androidx.media3.session.MediaControllerStub$$ExternalSyntheticLambda11.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Media

N/A

Bug Report

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.