mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Refactor shouldEnablePlayPauseButton out of PlayerControlView into Util
PiperOrigin-RevId: 691502799
This commit is contained in:
parent
2b27e33784
commit
6cbf77b3f0
@ -21,6 +21,7 @@ import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_DEPTH_LINEAR;
|
|||||||
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_DEPTH_METADATA;
|
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_DEPTH_METADATA;
|
||||||
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_ORIGINAL;
|
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_ORIGINAL;
|
||||||
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_UNDEFINED;
|
import static androidx.media3.common.C.AUXILIARY_TRACK_TYPE_UNDEFINED;
|
||||||
|
import static androidx.media3.common.Player.COMMAND_GET_TIMELINE;
|
||||||
import static androidx.media3.common.Player.COMMAND_PLAY_PAUSE;
|
import static androidx.media3.common.Player.COMMAND_PLAY_PAUSE;
|
||||||
import static androidx.media3.common.Player.COMMAND_PREPARE;
|
import static androidx.media3.common.Player.COMMAND_PREPARE;
|
||||||
import static androidx.media3.common.Player.COMMAND_SEEK_BACK;
|
import static androidx.media3.common.Player.COMMAND_SEEK_BACK;
|
||||||
@ -3548,6 +3549,20 @@ public final class Util {
|
|||||||
return Integer.toString(i, Character.MAX_RADIX);
|
return Integer.toString(i, Character.MAX_RADIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a play-pause button should be enabled or not.
|
||||||
|
*
|
||||||
|
* @param player The {@link Player}. May be {@code null}.
|
||||||
|
*/
|
||||||
|
@EnsuresNonNullIf(result = true, expression = "#1")
|
||||||
|
@UnstableApi
|
||||||
|
public static boolean shouldEnablePlayPauseButton(@Nullable Player player) {
|
||||||
|
return player != null
|
||||||
|
&& player.isCommandAvailable(COMMAND_PLAY_PAUSE)
|
||||||
|
&& (!player.isCommandAvailable(COMMAND_GET_TIMELINE)
|
||||||
|
|| !player.getCurrentTimeline().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a play button should be presented on a UI element for playback control. If
|
* Returns whether a play button should be presented on a UI element for playback control. If
|
||||||
* {@code false}, a pause button should be shown instead.
|
* {@code false}, a pause button should be shown instead.
|
||||||
|
@ -18,7 +18,6 @@ package androidx.media3.ui;
|
|||||||
import static androidx.media3.common.Player.COMMAND_GET_CURRENT_MEDIA_ITEM;
|
import static androidx.media3.common.Player.COMMAND_GET_CURRENT_MEDIA_ITEM;
|
||||||
import static androidx.media3.common.Player.COMMAND_GET_TIMELINE;
|
import static androidx.media3.common.Player.COMMAND_GET_TIMELINE;
|
||||||
import static androidx.media3.common.Player.COMMAND_GET_TRACKS;
|
import static androidx.media3.common.Player.COMMAND_GET_TRACKS;
|
||||||
import static androidx.media3.common.Player.COMMAND_PLAY_PAUSE;
|
|
||||||
import static androidx.media3.common.Player.COMMAND_SEEK_BACK;
|
import static androidx.media3.common.Player.COMMAND_SEEK_BACK;
|
||||||
import static androidx.media3.common.Player.COMMAND_SEEK_FORWARD;
|
import static androidx.media3.common.Player.COMMAND_SEEK_FORWARD;
|
||||||
import static androidx.media3.common.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM;
|
import static androidx.media3.common.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM;
|
||||||
@ -1178,7 +1177,7 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
playPauseButton.setImageDrawable(drawable);
|
playPauseButton.setImageDrawable(drawable);
|
||||||
playPauseButton.setContentDescription(resources.getString(stringRes));
|
playPauseButton.setContentDescription(resources.getString(stringRes));
|
||||||
|
|
||||||
boolean enablePlayPause = shouldEnablePlayPauseButton();
|
boolean enablePlayPause = Util.shouldEnablePlayPauseButton(player);
|
||||||
updateButton(enablePlayPause, playPauseButton);
|
updateButton(enablePlayPause, playPauseButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1732,13 +1731,6 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldEnablePlayPauseButton() {
|
|
||||||
return player != null
|
|
||||||
&& player.isCommandAvailable(COMMAND_PLAY_PAUSE)
|
|
||||||
&& (!player.isCommandAvailable(COMMAND_GET_TIMELINE)
|
|
||||||
|| !player.getCurrentTimeline().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
private static boolean isHandledMediaKey(int keyCode) {
|
private static boolean isHandledMediaKey(int keyCode) {
|
||||||
return keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
|
return keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
|
||||||
|
Loading…
x
Reference in New Issue
Block a user