@@ -3043,23 +3043,41 @@ public static String intToStringMaxRadix(int i) {
3043
3043
* <p>Use {@link #handlePlayPauseButtonAction}, {@link #handlePlayButtonAction} or {@link
3044
3044
* #handlePauseButtonAction} to handle the interaction with the play or pause button UI element.
3045
3045
*
3046
- * @param player The {@link Player}. May be null.
3046
+ * @param player The {@link Player}. May be {@code null} .
3047
3047
*/
3048
3048
@ EnsuresNonNullIf (result = false , expression = "#1" )
3049
3049
public static boolean shouldShowPlayButton (@ Nullable Player player ) {
3050
+ return shouldShowPlayButton (player , /* playIfSuppressed= */ true );
3051
+ }
3052
+
3053
+ /**
3054
+ * Returns whether a play button should be presented on a UI element for playback control. If
3055
+ * {@code false}, a pause button should be shown instead.
3056
+ *
3057
+ * <p>Use {@link #handlePlayPauseButtonAction}, {@link #handlePlayButtonAction} or {@link
3058
+ * #handlePauseButtonAction} to handle the interaction with the play or pause button UI element.
3059
+ *
3060
+ * @param player The {@link Player}. May be {@code null}.
3061
+ * @param playIfSuppressed Whether to show a play button if playback is {@linkplain
3062
+ * Player#getPlaybackSuppressionReason() suppressed}.
3063
+ */
3064
+ @ EnsuresNonNullIf (result = false , expression = "#1" )
3065
+ public static boolean shouldShowPlayButton (@ Nullable Player player , boolean playIfSuppressed ) {
3050
3066
return player == null
3051
3067
|| !player .getPlayWhenReady ()
3052
3068
|| player .getPlaybackState () == Player .STATE_IDLE
3053
- || player .getPlaybackState () == Player .STATE_ENDED ;
3069
+ || player .getPlaybackState () == Player .STATE_ENDED
3070
+ || (playIfSuppressed
3071
+ && player .getPlaybackSuppressionReason () != Player .PLAYBACK_SUPPRESSION_REASON_NONE );
3054
3072
}
3055
3073
3056
3074
/**
3057
3075
* Updates the player to handle an interaction with a play button.
3058
3076
*
3059
3077
* <p>This method assumes the play button is enabled if {@link #shouldShowPlayButton} returns
3060
- * true.
3078
+ * {@code true} .
3061
3079
*
3062
- * @param player The {@link Player}. May be null.
3080
+ * @param player The {@link Player}. May be {@code null} .
3063
3081
* @return Whether a player method was triggered to handle this action.
3064
3082
*/
3065
3083
public static boolean handlePlayButtonAction (@ Nullable Player player ) {
@@ -3087,9 +3105,9 @@ public static boolean handlePlayButtonAction(@Nullable Player player) {
3087
3105
* Updates the player to handle an interaction with a pause button.
3088
3106
*
3089
3107
* <p>This method assumes the pause button is enabled if {@link #shouldShowPlayButton} returns
3090
- * false.
3108
+ * {@code false} .
3091
3109
*
3092
- * @param player The {@link Player}. May be null.
3110
+ * @param player The {@link Player}. May be {@code null} .
3093
3111
* @return Whether a player method was triggered to handle this action.
3094
3112
*/
3095
3113
public static boolean handlePauseButtonAction (@ Nullable Player player ) {
@@ -3104,13 +3122,29 @@ public static boolean handlePauseButtonAction(@Nullable Player player) {
3104
3122
* Updates the player to handle an interaction with a play or pause button.
3105
3123
*
3106
3124
* <p>This method assumes that the UI element enables a play button if {@link
3107
- * #shouldShowPlayButton} returns true and a pause button otherwise.
3125
+ * #shouldShowPlayButton} returns {@code true} and a pause button otherwise.
3108
3126
*
3109
- * @param player The {@link Player}. May be null.
3127
+ * @param player The {@link Player}. May be {@code null} .
3110
3128
* @return Whether a player method was triggered to handle this action.
3111
3129
*/
3112
3130
public static boolean handlePlayPauseButtonAction (@ Nullable Player player ) {
3113
- if (shouldShowPlayButton (player )) {
3131
+ return handlePlayPauseButtonAction (player , /* playIfSuppressed= */ true );
3132
+ }
3133
+
3134
+ /**
3135
+ * Updates the player to handle an interaction with a play or pause button.
3136
+ *
3137
+ * <p>This method assumes that the UI element enables a play button if {@link
3138
+ * #shouldShowPlayButton(Player, boolean)} returns {@code true} and a pause button otherwise.
3139
+ *
3140
+ * @param player The {@link Player}. May be {@code null}.
3141
+ * @param playIfSuppressed Whether to trigger a play action if playback is {@linkplain
3142
+ * Player#getPlaybackSuppressionReason() suppressed}.
3143
+ * @return Whether a player method was triggered to handle this action.
3144
+ */
3145
+ public static boolean handlePlayPauseButtonAction (
3146
+ @ Nullable Player player , boolean playIfSuppressed ) {
3147
+ if (shouldShowPlayButton (player , playIfSuppressed )) {
3114
3148
return handlePlayButtonAction (player );
3115
3149
} else {
3116
3150
return handlePauseButtonAction (player );
0 commit comments