media icon indicating copy to clipboard operation
media copied to clipboard

Rename setShowPlayButtonIfPlaybackIsSuppressed in MediaSession.Builder

Open Ethan1983 opened this issue 1 year ago • 0 comments

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

Alternatives considered

Ethan1983 avatar Feb 22 '24 05:02 Ethan1983