-
Notifications
You must be signed in to change notification settings - Fork 624
session: fix IllegalStateException when calling setSessionExtras() #2265
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me to the line where the
IllegalStateException
is originating?I can't find a line where this would be caused by
sessionCompat.setPlaybackState(state)
. Similarly, forplayerWrapper.createPlaybackStateCompat()
. I probably just haven't find it.Best would be a stack trace of when this IllegalStateException happens.
I'm asking because if that would be an issue then there is a general problem in other methods around that call site I think. We'd need to investigate this some further, so a stack trace would be very helpful.
You say this is for when calling from a thread different than the main thread. The session is using the application thread which which the player was build [1], so if there was an issue regarding main thread vs. application thread, then we either have a more fundamental problem to discover, or then the player/session may not have been setup properly in the app.
I'd be great to clarify this first to see whether and where we need changes.
[1] https://github.com/androidx/media/blob/release/libraries/session/src/main/java/androidx/media3/session/MediaSessionImpl.java#L202-L203
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @marcbaechinger,
the full stack trace is:
I have edited the demo app to create the player on a different thread. However, the MediaSession will still be created on the main thread, and setSessionExtras will be called on the main thread, too.
I have thought about wheter it is just incorrect to call this on the main thread if the application thread is not the main thread, but:
updateLegacySessionPlaybackState
which is a postOrRun variant of this. Only onSessionExtrasChanged does not use postOrRun which leads to this crash. Aligning this with the other methods makes the crash go away.Based on the fact that:
I think this makes sense to fix like this, instead of calling setSessionExtras on another thread. Many generic methods like the constructor of MediaSession work on any thread, and it makes the app code simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for the response and the stack trace to help me understand the issue better. It's coming from calling methods on the player in
createPlaybackStateCompat
.I figure then we'd have the same issue when calling for instance
MediaSession.sendError()
that is calling through toControllerLegacyCbForBroadcast.onError()
which then callsplayerWrapper.createPlaybackStateCompat()
from the main thread as well.Ok, thanks for reporting. I'm going to take that PR, send it for review and then will file an internal bug, so we can look into other possible cases we have to cover. Thank you.