androidx / androidx/media

Rename setShowPlayButtonIfPlaybackIsSuppressed in MediaSession.Builder

Open
#1,118 0 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

enhancement needs triage
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

[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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.