MediaSession extension: Allow setting of custom errors.
Add methods setCustomErrorMessage(@Nullable CharSequence message) and setCustomErrorMessage(@Nullable CharSequence message, int code) to MediaSessionConnector to report errors to the MediaSession which are not player errors. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=202352083
This commit is contained in:
parent
6b9fb456a1
commit
4e35d1a47b
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
### dev-v2 (not yet released) ###
|
### dev-v2 (not yet released) ###
|
||||||
|
|
||||||
|
* MediaSession extension:
|
||||||
|
* Allow apps to set custom errors.
|
||||||
* Allow apps to pass a `CacheKeyFactory` for setting custom cache keys when
|
* Allow apps to pass a `CacheKeyFactory` for setting custom cache keys when
|
||||||
creating a `CacheDataSource`.
|
creating a `CacheDataSource`.
|
||||||
* Turned on Java 8 compiler support for the ExoPlayer library. Apps that depend
|
* Turned on Java 8 compiler support for the ExoPlayer library. Apps that depend
|
||||||
|
@ -308,6 +308,7 @@ public final class MediaSessionConnector {
|
|||||||
private CustomActionProvider[] customActionProviders;
|
private CustomActionProvider[] customActionProviders;
|
||||||
private Map<String, CustomActionProvider> customActionMap;
|
private Map<String, CustomActionProvider> customActionMap;
|
||||||
private @Nullable ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider;
|
private @Nullable ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider;
|
||||||
|
private @Nullable Pair<Integer, CharSequence> customError;
|
||||||
private PlaybackPreparer playbackPreparer;
|
private PlaybackPreparer playbackPreparer;
|
||||||
private QueueNavigator queueNavigator;
|
private QueueNavigator queueNavigator;
|
||||||
private QueueEditor queueEditor;
|
private QueueEditor queueEditor;
|
||||||
@ -488,6 +489,31 @@ public final class MediaSessionConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a custom error on the session.
|
||||||
|
*
|
||||||
|
* <p>This sets the error code via {@link PlaybackStateCompat.Builder#setErrorMessage(int,
|
||||||
|
* CharSequence)}. By default, the error code will be set to {@link
|
||||||
|
* PlaybackStateCompat#ERROR_CODE_APP_ERROR}.
|
||||||
|
*
|
||||||
|
* @param message The error string to report or {@code null} to clear the error.
|
||||||
|
*/
|
||||||
|
public void setCustomErrorMessage(@Nullable CharSequence message) {
|
||||||
|
int code = (message == null) ? 0 : PlaybackStateCompat.ERROR_CODE_APP_ERROR;
|
||||||
|
setCustomErrorMessage(message, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a custom error on the session.
|
||||||
|
*
|
||||||
|
* @param message The error string to report or {@code null} to clear the error.
|
||||||
|
* @param code The error code to report. Ignored when {@code message} is {@code null}.
|
||||||
|
*/
|
||||||
|
public void setCustomErrorMessage(@Nullable CharSequence message, int code) {
|
||||||
|
customError = (message == null) ? null : new Pair<>(code, message);
|
||||||
|
invalidateMediaSessionPlaybackState();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the metadata of the media session.
|
* Updates the metadata of the media session.
|
||||||
*
|
*
|
||||||
@ -527,11 +553,14 @@ public final class MediaSessionConnector {
|
|||||||
int playbackState = player.getPlaybackState();
|
int playbackState = player.getPlaybackState();
|
||||||
ExoPlaybackException playbackError =
|
ExoPlaybackException playbackError =
|
||||||
playbackState == Player.STATE_IDLE ? player.getPlaybackError() : null;
|
playbackState == Player.STATE_IDLE ? player.getPlaybackError() : null;
|
||||||
|
boolean reportError = playbackError != null || customError != null;
|
||||||
int sessionPlaybackState =
|
int sessionPlaybackState =
|
||||||
playbackError != null
|
reportError
|
||||||
? PlaybackStateCompat.STATE_ERROR
|
? PlaybackStateCompat.STATE_ERROR
|
||||||
: mapPlaybackState(player.getPlaybackState(), player.getPlayWhenReady());
|
: mapPlaybackState(player.getPlaybackState(), player.getPlayWhenReady());
|
||||||
if (playbackError != null && errorMessageProvider != null) {
|
if (customError != null) {
|
||||||
|
builder.setErrorMessage(customError.first, customError.second);
|
||||||
|
} else if (playbackError != null && errorMessageProvider != null) {
|
||||||
Pair<Integer, String> message = errorMessageProvider.getErrorMessage(playbackError);
|
Pair<Integer, String> message = errorMessageProvider.getErrorMessage(playbackError);
|
||||||
builder.setErrorMessage(message.first, message.second);
|
builder.setErrorMessage(message.first, message.second);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user