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

What is the right way of notifying media session about non-fatal errors in Media3? #873

Closed
bstokrocki opened this issue Dec 7, 2023 · 3 comments
Assignees

Comments

@bstokrocki
Copy link

Our media application is available on both Android mobile (with support of Android Auto) and on Android Automotive. We already migrated to Media3, so we're using MediaLibraryService, however there's this one case we're not sure how to cover in Media3.
We have some custom actions that are not always available, like adding content to favorites, which requires user to be logged in. We're providing an alternative variant of action's icon to indicate that it's not available at the moment, but user can of course still click on it. What we previously did in this case is setting a non-fatal error in the media session like this:

mediaSession.setPlaybackState(
     // We would take the current playback state rather than setting STATE_ERROR
     // as the error we surface is non-fatal, playback can continue normally, we're only
     // interested in providing an error message 
     PlaybackStateCompat.Builder(controller.playbackState)
         .setErrorMessage(errorCode, errorMessage)
         .build()
 )

This was especially important on Android Automotive as this allowed us to surface meaningful error message to the user in form of a toast. However, due to automatic state handling in Media3, this no longer seems to be possible. I noticed that this issue is being mentioned in the docs: https://developer.android.com/guide/topics/media/session/mediasession#automatic-state.
I was wondering if there's already any solution that I could go for to cover this case in Media3?

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Dec 7, 2023

Thanks for your report.

That's a known issue and there is currently no good way to do this with Media3 I'm afraid.
We agree it's useful to have this for the use cases you explained.

We already have #543 so I mark this as a duplicate. We hope to have this ready for the next release.

A question around your actual implementation with the legacy library: once you have sent the error code and message as above, how long do you keep that error in the PlaybackStateCompat? Are you simply clearing this message with the next update of the playback state or do you keep it until a certain event in your app happens?

@bstokrocki
Copy link
Author

Hi, thank you for the answer and sorry for the duplicate!

Glad to hear that solution might be soon available.

To answer your question - the error was cleared by the next update of the playback state.

@marcbaechinger
Copy link
Contributor

Many thanks! Very useful!

I'm closing in favor of the other issue.

@androidx androidx locked and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants