media: Media3 MediaSession custom error messages
Is there an equivalent in media3 for these?
MediaSessionConnector.setCustomErrorMessage()to send a custom error message regardless of player state.MediaSessionConnector.setErrorMessageProvider(PlayerErrorMessageProvider)to convert PlaybackException to a custom error message for connected controllers.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 36 (15 by maintainers)
Commits related to this issue
- Add MediaSession.sendError to send non-fatal error data to controllers This allows to set custom error message for instance on Android Auto/Automotive OS. Issue: androidx/media#543 PiperOrigin-RevId... — committed to androidx/media by marcbaechinger 3 years ago
- Reset platform playback state immediately after sending custom error This change resets the error in the platform error state immediately to make sure that the custom error is reflected only very bri... — committed to androidx/media by marcbaechinger 3 years ago
This is planned for 1.4 which is the next release.
Yeah, I meant returning that from
onGetChildren()from theMediaLibrarySession.Callback.I think the remaining piece of this issue is adding ways for apps to generate their own custom
PlaybackExceptioneven if there isn’t aPlaybackExceptioncoming from the player. This is a remaining of the legacy library that leaks into the new API with this. In media1 policy errors in theMediaBrowserServiceCompathave been reported as fatal exception in the playback state. This wasn’t nicely separated in concerns IMO. So we added the workaround that returning an authentication error from theMediaLibraryCallback.onXyz()triggers a fatal exception in the platform playback state.So I think regarding the custom
PlaybackExceptionthere isn’t a need to create a new issue.I’ll do my best to deliver this asap.
I think Media3 is currently missing an API to send a custom fatal exception in an easy way.
The current version allows to send non-fatal errors as you do and it allows to customize error code and error message of a
PlaybackException. However, there isn’t an easy way do originate a fatalPlaybackExceptionthat isn’t coming from thePlayer.https://developer.android.com/media/media3/session/control-playback#error-handling
Sorry for not having a better answer than that we should prioritize this to provide this with the next release.
The consumer for
MediaSessionConnector.setCustomErrorMessage()is AndroidAuto. It sends respective error messages to be displayed on the AndroidAuto screen when something goes wrong with a play action. (for example user not logged in, no book available for resumption, playback error custom message). Right now with media3, the error message just says “Source error” and I want it to be more user friendly.The consumer for
MediaSessionConnector.setErrorMessageProvider(PlayerErrorMessageProvider)is the MediaControllerCompat in my app (I haven´t migrated that part to media3 yet). I map the PlaybackException to a respective error message that is user friendly, and display it in an alert dialog. I see that media3 MediaController has a onPlayerError(PlaybackException) so I am guessing that could be the solution and handle the PlaybackException on the MediaBrowser side.https://github.com/androidx/media/commit/5d5a430756cdd42e5ae80727b36b8a8fe151085c https://github.com/androidx/media/commit/317b40f26961c6c4db630eea618c612ac038d260
We’ve added
MediaSession.setPlaybackException(ControllerInfo, PlaybackException)that allows setting customPlaybackExceptionfor selected or all controllers. Please see the JavaDoc in the main branch for now to learnhow to set a fatal error.I’m closing this issue. A Media3 app can now 1) send non-fatal policy errors that are not affecting playback, 2) rewrite and change error codes and message of actual
PlaybackExceptioninstances thrown by the player and 3) set customPlaybackExceptionfor a certain Media3 controller (use the media notification controller to set an error for the legacy session).We will add documentation for 3) to the official documentation on this page, once we have released that change.
The change will be included in the next release for which the first alpha has been cut already.
If you find an problem with this or have some further input, please file another issue and describe the issue as usual as per issue template.
Yeah, sorry no news yet.
I don’t think this will be part of 1.3 I’m afraid. We will update this issue as soon as we pushed a change that adds this.
no problems with asking questions, I’m glad to help 😃
first of all, the impact of the non-fatal you are describing above with the
session.sendError. since we cannot provide the media items for the unauthorized user, we return an empty listthis will result in a stuck “Getting your selection” screen (unless you tap the back button), and an error toast shown at the bottom for a couple of seconds:
this approach has a serious flaw when used from
onAddMediaItems: this error is displayed for a short period time, while the driver might be unable to give a quick look at the AA display due to the traffic or whatever. this means that once they finally are able to take a look at why the music has stopped, they won’t see any error message. in terms of Google Play Store reviewers, this is unacceptableyes, that’s correct. here’s a flashback to our previous media2 implementation. things were simpler since we could hack into
session.sessionCompatand set the error playback state ourselves. the code for this used to look smth like this:this would result in opening a fullscreen AA player with the error state that would persist until the user took some action (e.g. navigating back and playing smth else)
this behavior based on the following guidelines: https://developer.android.com/training/cars/media#errors
please let me know if you need any additional input from me
Thanks for the quick reply, with our old ExoPlayer implementation we would authenticate for playback, if it failed we would call mediaSessionConnector.setCustomErrorMessage(errorMessage). That resulted in a message being shown in the android auto ui (see attached screenshot).
With media3, we authenticate for playback in onSetMediaItems (when it’s called from an Android auto controller). The difference here is calling mediaSession.sendError() displays a toast instead and the screen remains in “Getting your selection” (as shown in first screenshot). I’ve tried returning a Futures.immediateFailedFuture in onSetMediaItems but it doesn’t have any effect. The only way I can get the screen to show the “Source error” is by returning a broken MediaItem that can’t be played.
We are currently preparing the beta01. The stable release of 1.4.0 is expected to be in mid July.
Our app update got rejected in playstore review because we didn’t send error messages when using android auto. In other words this should be a blocker for many media app(s).
Yes, this is a regression compared with what’s possible with the legacy API. We need to look into this. Marked as enhancement.