Skip to content
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

IllegalStateException about wrong thread Player access upon MediaSessionService connection #318

Closed
1 task
bubenheimer opened this issue Apr 12, 2023 · 2 comments
Assignees
Labels

Comments

@bubenheimer
Copy link

bubenheimer commented Apr 12, 2023

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

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@tonihei
Copy link
Collaborator

tonihei commented Apr 13, 2023

Thanks for reporting! We identified the underlying issue and can provide a fix for it in the next bugfix release.

@tonihei tonihei assigned tonihei and unassigned tianyif Apr 13, 2023
rohitjoins pushed a commit that referenced this issue Apr 17, 2023
The sessions may have different application threads for their players,
and the service with its notification provider runs on the main thread.
To ensure everything runs on the correct thread, this change labels
methods where needed and fixes thread access in some places.

Issue: #318
PiperOrigin-RevId: 524849598
rohitjoins pushed a commit to google/ExoPlayer that referenced this issue Apr 17, 2023
The sessions may have different application threads for their players,
and the service with its notification provider runs on the main thread.
To ensure everything runs on the correct thread, this change labels
methods where needed and fixes thread access in some places.

Issue: androidx/media#318
PiperOrigin-RevId: 524849598
rohitjoins pushed a commit that referenced this issue Apr 18, 2023
The sessions may have different application threads for their players,
and the service with its notification provider runs on the main thread.
To ensure everything runs on the correct thread, this change labels
methods where needed and fixes thread access in some places.

Issue: #318
PiperOrigin-RevId: 524849598
(cherry picked from commit ffa3743)
rohitjoins pushed a commit to google/ExoPlayer that referenced this issue Apr 18, 2023
The sessions may have different application threads for their players,
and the service with its notification provider runs on the main thread.
To ensure everything runs on the correct thread, this change labels
methods where needed and fixes thread access in some places.

Issue: androidx/media#318
PiperOrigin-RevId: 524849598
(cherry picked from commit 73c216d)
rohitjoins pushed a commit that referenced this issue Apr 18, 2023
The sessions may have different application threads for their players,
and the service with its notification provider runs on the main thread.
To ensure everything runs on the correct thread, this change labels
methods where needed and fixes thread access in some places.

Issue: #318
PiperOrigin-RevId: 524849598
(cherry picked from commit ffa3743)
@bubenheimer
Copy link
Author

1.0.1 does fix this issue. Thank you!

@tonihei tonihei closed this as completed Apr 20, 2023
@androidx androidx locked and limited conversation to collaborators Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants