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

Media3 MediaSession custom error messages #543

Open
abouda opened this issue Jul 26, 2023 · 21 comments
Open

Media3 MediaSession custom error messages #543

abouda opened this issue Jul 26, 2023 · 21 comments
Assignees

Comments

@abouda
Copy link

abouda commented Jul 26, 2023

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.
@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jul 26, 2023

There is no such functionality in Media3.

Who would be the consumer of the error messages?

@abouda
Copy link
Author

abouda commented Jul 26, 2023

  • 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.

@abouda
Copy link
Author

abouda commented Jul 26, 2023

Also another point is although I could handle the error onPlayerError(PlaybackException) in my app, it does not solve it for legacy controllers like AndroidAuto.

@marcbaechinger
Copy link
Contributor

Yes, this is a regression compared with what's possible with the legacy API.
We need to look into this. Marked as enhancement.

@Bwaim
Copy link

Bwaim commented Feb 9, 2024

@marcbaechinger do you hav any news on this ?

@marcbaechinger
Copy link
Contributor

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.

@Flyktsodan
Copy link

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).

@benjaminVadon
Copy link

@marcbaechinger have you any update about this limitation ? Is it planned for the next version ?

@marcbaechinger
Copy link
Contributor

This is planned for 1.4 which is the next release.

copybara-service bot pushed a commit that referenced this issue May 14, 2024
This allows to set custom error message for instance on Android
Auto/Automotive OS.

Issue: #543
PiperOrigin-RevId: 633610089
@marcbaechinger
Copy link
Contributor

The commit above added an API to send non-fatal errors to a MediaController.

When sent to all controllers or specifically to the media notification controller (MediaSession.getMediaNotificationControllerInfo()), the error code, message and extras are included in the PlaybackStateCompat with state=STATE_ERROR (7) and sent to the platform/legacy session from where a platform or legacy controller (for instance Android Auto) can read it.

copybara-service bot pushed a commit that referenced this issue May 14, 2024
This change resets the error in the platform error state immediately
to make sure that the custom error is reflected only very briefly
and then gets back to the playback state that actually reflects the
player state.

Issue: #543
PiperOrigin-RevId: 633626180
@icutvaric
Copy link

Hello!

Any updates on this?

Or any suggestion how to do authentication on Automotive OS with Media3: https://developer.android.com/training/cars/media/automotive-os#require-sign-in?

Thanks!

@kelmer44
Copy link

Is there a reason why a resource Id is necessary? Could the method not accept just a plain string as well?

@marcbaechinger
Copy link
Contributor

This API has changed. The change that includes this is on its way into the main branch.

There will be a SessionError instead of the three parameters: MediaSession.sendError(ControllerInfo, SessionError). The message argument of the constructor of MediaSession is a String instead of a resource ID. Please use a localized string either way for the benefit of your users.

@kelmer44
Copy link

@marcbaechinger thats great! I do plan on using a localized string, only we dont use the android resources in our project, but an alternative solution

@chillbrodev
Copy link

This is planned for 1.4 which is the next release.

Is there a potential release date for 1.4?

@marcbaechinger
Copy link
Contributor

We are currently preparing the beta01. The stable release of 1.4.0 is expected to be in mid July.

@Flyktsodan
Copy link

I tried the latest version and it works in terms of showing a error message. The android auto companion app still shows "Getting your selection" and users have to navigate back and try again. Is there any way of communicating that the ListenableFuture failed and it should close the "player view" in android auto? See screenshot for reference:
Screenshot 2024-08-21 at 11 17 50

@marcbaechinger
Copy link
Contributor

Thanks for reporting.

What did you do this in the old world to make 'close the "player view" in android auto'?

Not sure if this is what you are asking about, but I mean to remember that you can send a PendingIntent back to Auto that then opens that activity for resolving the error in some ways. Is this what you are asking for?

This is documented here: https://developers.google.com/cars/design/create-apps/media-apps/signin-flow

If this is the case, then you can add the same extras key/value to the LibraryResult that does report the authentication error code. Something like this:

return Futures.immediateFuture(
  LibraryResult.ofError(
    LibraryResult.RESULT_ERROR_SESSION_AUTHENTICATION_EXPIRED,
    LibraryParams.Builder()
       .setExtras(getExpiredAuthenticationResolutionExtras()).build()
  )
)

private fun getExpiredAuthenticationResolutionExtras(): Bundle {
        return Bundle().also {
            it.putString(
                EXTRAS_KEY_ERROR_RESOLUTION_ACTION_LABEL_COMPAT,
                getString(R.string.login_button_label))
            val signInIntent = Intent(this, SignInActivity::class.java)
            @OptIn(UnstableApi::class)
            val flags = if (Util.SDK_INT >= 23) PendingIntent.FLAG_IMMUTABLE else 0
            it.putParcelable(
                EXTRAS_KEY_ERROR_RESOLUTION_ACTION_INTENT_COMPAT,
                PendingIntent.getActivity(this, /* requestCode= */ 0, signInIntent, flags))
        }
    }

@Flyktsodan
Copy link

Flyktsodan commented Aug 21, 2024

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.

Screenshot 2024-08-21 at 12 06 36

@Flyktsodan
Copy link

@marcbaechinger can you think of any way in how to replicate the old behaviour described above?
I'm worried app will be rejected in playstore review if this is not fixed somehow.

@marcbaechinger
Copy link
Contributor

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 fatal PlaybackException that isn't coming from the Player.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants