media
media copied to clipboard
Rename setShowPlayButtonIfPlaybackIsSuppressed in MediaSession.Builder
[REQUIRED] Use case description
Please consider renaming setShowPlayButtonIfPlaybackIsSuppressed of MediaSession.Builder as the intent is more closely related to playback state when playback is suppressed.
https://developer.android.com/reference/androidx/media3/session/MediaSession.Builder#setShowPlayButtonIfPlaybackIsSuppressed(boolean)
For instance, playIfSuppressed is used to get the current playback state which is eventually exposed to media controllers.
/** Converts {@link Player}' states to state of {@link PlaybackStateCompat}. */
@PlaybackStateCompat.State
public static int convertToPlaybackStateCompatState(Player player, boolean playIfSuppressed) {
if (player.getPlayerError() != null) {
return PlaybackStateCompat.STATE_ERROR;
}
@Player.State int playbackState = player.getPlaybackState();
boolean shouldShowPlayButton = Util.shouldShowPlayButton(player, playIfSuppressed);
switch (playbackState) {
case Player.STATE_IDLE:
return PlaybackStateCompat.STATE_NONE;
case Player.STATE_READY:
return shouldShowPlayButton
? PlaybackStateCompat.STATE_PAUSED
: PlaybackStateCompat.STATE_PLAYING;
case Player.STATE_ENDED:
return PlaybackStateCompat.STATE_STOPPED;
case Player.STATE_BUFFERING:
return shouldShowPlayButton
? PlaybackStateCompat.STATE_PAUSED
: PlaybackStateCompat.STATE_BUFFERING;
default:
throw new IllegalArgumentException("Unrecognized State: " + playbackState);
}
}
Proposed solution
setPlaybackStateAsPausedIfPlaybackIsSuppressed or a better name. Internally, it could also imply an obvious side-effect on UI buttons.