Commit b6290b11 by kimvde Committed by Ian Baker

Add commands only available in SimpleExoPlayer

PiperOrigin-RevId: 364598601
parent 75dd1b43
...@@ -75,8 +75,9 @@ public final class CastPlayer extends BasePlayer { ...@@ -75,8 +75,9 @@ public final class CastPlayer extends BasePlayer {
} }
@VisibleForTesting @VisibleForTesting
/* package */ static final int[] PERMANENT_AVAILABLE_COMMANDS = /* package */ static final Commands PERMANENT_AVAILABLE_COMMANDS =
new int[] { new Commands.Builder()
.addAll(
COMMAND_PLAY_PAUSE, COMMAND_PLAY_PAUSE,
COMMAND_PREPARE_STOP_RELEASE, COMMAND_PREPARE_STOP_RELEASE,
COMMAND_SEEK_TO_MEDIA_ITEM, COMMAND_SEEK_TO_MEDIA_ITEM,
...@@ -84,8 +85,8 @@ public final class CastPlayer extends BasePlayer { ...@@ -84,8 +85,8 @@ public final class CastPlayer extends BasePlayer {
COMMAND_GET_CURRENT_MEDIA_ITEM, COMMAND_GET_CURRENT_MEDIA_ITEM,
COMMAND_GET_MEDIA_ITEMS, COMMAND_GET_MEDIA_ITEMS,
COMMAND_GET_MEDIA_ITEMS_METADATA, COMMAND_GET_MEDIA_ITEMS_METADATA,
COMMAND_CHANGE_MEDIA_ITEMS COMMAND_CHANGE_MEDIA_ITEMS)
}; .build();
private static final String TAG = "CastPlayer"; private static final String TAG = "CastPlayer";
......
...@@ -328,7 +328,7 @@ public abstract class BasePlayer implements Player { ...@@ -328,7 +328,7 @@ public abstract class BasePlayer implements Player {
return repeatMode == REPEAT_MODE_ONE ? REPEAT_MODE_OFF : repeatMode; return repeatMode == REPEAT_MODE_ONE ? REPEAT_MODE_OFF : repeatMode;
} }
protected Commands getAvailableCommands(@Command int[] permanentAvailableCommands) { protected Commands getAvailableCommands(Commands permanentAvailableCommands) {
return new Commands.Builder() return new Commands.Builder()
.addAll(permanentAvailableCommands) .addAll(permanentAvailableCommands)
.addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentWindowSeekable() && !isPlayingAd()) .addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentWindowSeekable() && !isPlayingAd())
......
...@@ -752,6 +752,18 @@ public interface Player { ...@@ -752,6 +752,18 @@ public interface Player {
} }
/** /**
* Adds {@link Commands}.
*
* @param commands The set of {@link Command commands} to add.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder addAll(Commands commands) {
flagsBuilder.addAll(commands.flags);
return this;
}
/**
* Builds a {@link Commands} instance. * Builds a {@link Commands} instance.
* *
* @throws IllegalStateException If this method has already been called. * @throws IllegalStateException If this method has already been called.
...@@ -761,6 +773,9 @@ public interface Player { ...@@ -761,6 +773,9 @@ public interface Player {
} }
} }
/** An empty set of commands. */
public static final Commands EMPTY = new Builder().build();
private final ExoFlags flags; private final ExoFlags flags;
private Commands(ExoFlags flags) { private Commands(ExoFlags flags) {
...@@ -1034,7 +1049,10 @@ public interface Player { ...@@ -1034,7 +1049,10 @@ public interface Player {
* #COMMAND_SEEK_TO_MEDIA_ITEM}, {@link #COMMAND_SET_SPEED_AND_PITCH}, {@link * #COMMAND_SEEK_TO_MEDIA_ITEM}, {@link #COMMAND_SET_SPEED_AND_PITCH}, {@link
* #COMMAND_SET_SHUFFLE_MODE}, {@link #COMMAND_SET_REPEAT_MODE}, {@link * #COMMAND_SET_SHUFFLE_MODE}, {@link #COMMAND_SET_REPEAT_MODE}, {@link
* #COMMAND_GET_CURRENT_MEDIA_ITEM}, {@link #COMMAND_GET_MEDIA_ITEMS}, {@link * #COMMAND_GET_CURRENT_MEDIA_ITEM}, {@link #COMMAND_GET_MEDIA_ITEMS}, {@link
* #COMMAND_GET_MEDIA_ITEMS_METADATA} or {@link #COMMAND_CHANGE_MEDIA_ITEMS}. * #COMMAND_GET_MEDIA_ITEMS_METADATA}, {@link #COMMAND_CHANGE_MEDIA_ITEMS}, {@link
* #COMMAND_GET_VOLUME}, {@link #COMMAND_GET_DEVICE_VOLUME}, {@link #COMMAND_SET_VOLUME}, {@link
* #COMMAND_SET_DEVICE_VOLUME}, {@link #COMMAND_ADJUST_DEVICE_VOLUME}, {@link
* #COMMAND_SET_VIDEO_SURFACE} or {@link #COMMAND_GET_TEXT}.
*/ */
@Documented @Documented
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
...@@ -1051,7 +1069,14 @@ public interface Player { ...@@ -1051,7 +1069,14 @@ public interface Player {
COMMAND_GET_CURRENT_MEDIA_ITEM, COMMAND_GET_CURRENT_MEDIA_ITEM,
COMMAND_GET_MEDIA_ITEMS, COMMAND_GET_MEDIA_ITEMS,
COMMAND_GET_MEDIA_ITEMS_METADATA, COMMAND_GET_MEDIA_ITEMS_METADATA,
COMMAND_CHANGE_MEDIA_ITEMS COMMAND_CHANGE_MEDIA_ITEMS,
COMMAND_GET_VOLUME,
COMMAND_GET_DEVICE_VOLUME,
COMMAND_SET_VOLUME,
COMMAND_SET_DEVICE_VOLUME,
COMMAND_ADJUST_DEVICE_VOLUME,
COMMAND_SET_VIDEO_SURFACE,
COMMAND_GET_TEXT
}) })
@interface Command {} @interface Command {}
/** Command to start, pause or resume playback. */ /** Command to start, pause or resume playback. */
...@@ -1080,6 +1105,20 @@ public interface Player { ...@@ -1080,6 +1105,20 @@ public interface Player {
int COMMAND_GET_MEDIA_ITEMS_METADATA = 12; int COMMAND_GET_MEDIA_ITEMS_METADATA = 12;
/** Command to change the {@link MediaItem MediaItems} in the playlist. */ /** Command to change the {@link MediaItem MediaItems} in the playlist. */
int COMMAND_CHANGE_MEDIA_ITEMS = 13; int COMMAND_CHANGE_MEDIA_ITEMS = 13;
/** Command to get the player volume. */
int COMMAND_GET_VOLUME = 14;
/** Command to get the device volume. */
int COMMAND_GET_DEVICE_VOLUME = 15;
/** Command to set the player volume. */
int COMMAND_SET_VOLUME = 16;
/** Command to set the device volume. */
int COMMAND_SET_DEVICE_VOLUME = 17;
/** Command to increment or decrement the device volume. */
int COMMAND_ADJUST_DEVICE_VOLUME = 18;
/** Command to set the surface on which to render the video. */
int COMMAND_SET_VIDEO_SURFACE = 19;
/** Command to get the text that should currently be displayed by the player. */
int COMMAND_GET_TEXT = 20;
/** Returns the component of this player for audio output, or null if audio is not supported. */ /** Returns the component of this player for audio output, or null if audio is not supported. */
@Nullable @Nullable
......
...@@ -85,6 +85,20 @@ public final class ExoFlags { ...@@ -85,6 +85,20 @@ public final class ExoFlags {
} }
/** /**
* Adds {@link ExoFlags flags}.
*
* @param flags The set of flags to add.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder addAll(ExoFlags flags) {
for (int i = 0; i < flags.size(); i++) {
add(flags.get(i));
}
return this;
}
/**
* Builds an {@link ExoFlags} instance. * Builds an {@link ExoFlags} instance.
* *
* @throws IllegalStateException If this method has already been called. * @throws IllegalStateException If this method has already been called.
......
...@@ -463,7 +463,8 @@ public interface ExoPlayer extends Player { ...@@ -463,7 +463,8 @@ public interface ExoPlayer extends Player {
pauseAtEndOfMediaItems, pauseAtEndOfMediaItems,
clock, clock,
looper, looper,
/* wrappingPlayer= */ null); /* wrappingPlayer= */ null,
/* additionalPermanentAvailableCommands= */ Commands.EMPTY);
if (setForegroundModeTimeoutMs > 0) { if (setForegroundModeTimeoutMs > 0) {
player.experimentalSetForegroundModeTimeoutMs(setForegroundModeTimeoutMs); player.experimentalSetForegroundModeTimeoutMs(setForegroundModeTimeoutMs);
......
...@@ -261,6 +261,7 @@ public final class ExoPlayerFactory { ...@@ -261,6 +261,7 @@ public final class ExoPlayerFactory {
/* pauseAtEndOfMediaItems= */ false, /* pauseAtEndOfMediaItems= */ false,
Clock.DEFAULT, Clock.DEFAULT,
applicationLooper, applicationLooper,
/* wrappingPlayer= */ null); /* wrappingPlayer= */ null,
/* additionalPermanentAvailableCommands= */ Player.Commands.EMPTY);
} }
} }
...@@ -26,7 +26,6 @@ import android.os.Handler; ...@@ -26,7 +26,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.PlayerMessage.Target;
import com.google.android.exoplayer2.analytics.AnalyticsCollector; import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
...@@ -57,20 +56,6 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -57,20 +56,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
*/ */
/* package */ final class ExoPlayerImpl extends BasePlayer implements ExoPlayer { /* package */ final class ExoPlayerImpl extends BasePlayer implements ExoPlayer {
@VisibleForTesting
/* package */ static final int[] PERMANENT_AVAILABLE_COMMANDS =
new int[] {
COMMAND_PLAY_PAUSE,
COMMAND_PREPARE_STOP_RELEASE,
COMMAND_SET_SPEED_AND_PITCH,
COMMAND_SET_SHUFFLE_MODE,
COMMAND_SET_REPEAT_MODE,
COMMAND_GET_CURRENT_MEDIA_ITEM,
COMMAND_GET_MEDIA_ITEMS,
COMMAND_GET_MEDIA_ITEMS_METADATA,
COMMAND_CHANGE_MEDIA_ITEMS
};
private static final String TAG = "ExoPlayerImpl"; private static final String TAG = "ExoPlayerImpl";
/** /**
...@@ -81,6 +66,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -81,6 +66,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
* operation. * operation.
*/ */
/* package */ final TrackSelectorResult emptyTrackSelectorResult; /* package */ final TrackSelectorResult emptyTrackSelectorResult;
/* package */ final Commands permanentAvailableCommands;
private final Renderer[] renderers; private final Renderer[] renderers;
private final TrackSelector trackSelector; private final TrackSelector trackSelector;
...@@ -139,6 +125,8 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -139,6 +125,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
* which is used to call listeners on. * which is used to call listeners on.
* @param wrappingPlayer The {@link Player} wrapping this one if applicable. This player instance * @param wrappingPlayer The {@link Player} wrapping this one if applicable. This player instance
* should be used for all externally visible callbacks. * should be used for all externally visible callbacks.
* @param additionalPermanentAvailableCommands The {@link Commands} that are permanently available
* in the wrapping player but that are not in this player.
*/ */
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
public ExoPlayerImpl( public ExoPlayerImpl(
...@@ -155,7 +143,8 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -155,7 +143,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
boolean pauseAtEndOfMediaItems, boolean pauseAtEndOfMediaItems,
Clock clock, Clock clock,
Looper applicationLooper, Looper applicationLooper,
@Nullable Player wrappingPlayer) { @Nullable Player wrappingPlayer,
Commands additionalPermanentAvailableCommands) {
Log.i( Log.i(
TAG, TAG,
"Init " "Init "
...@@ -192,9 +181,23 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -192,9 +181,23 @@ import java.util.concurrent.CopyOnWriteArraySet;
new ExoTrackSelection[renderers.length], new ExoTrackSelection[renderers.length],
/* info= */ null); /* info= */ null);
period = new Timeline.Period(); period = new Timeline.Period();
permanentAvailableCommands =
new Commands.Builder()
.addAll(
COMMAND_PLAY_PAUSE,
COMMAND_PREPARE_STOP_RELEASE,
COMMAND_SET_SPEED_AND_PITCH,
COMMAND_SET_SHUFFLE_MODE,
COMMAND_SET_REPEAT_MODE,
COMMAND_GET_CURRENT_MEDIA_ITEM,
COMMAND_GET_MEDIA_ITEMS,
COMMAND_GET_MEDIA_ITEMS_METADATA,
COMMAND_CHANGE_MEDIA_ITEMS)
.addAll(additionalPermanentAvailableCommands)
.build();
availableCommands = availableCommands =
new Commands.Builder() new Commands.Builder()
.addAll(PERMANENT_AVAILABLE_COMMANDS) .addAll(permanentAvailableCommands)
.add(COMMAND_SEEK_TO_MEDIA_ITEM) .add(COMMAND_SEEK_TO_MEDIA_ITEM)
.build(); .build();
maskingWindowIndex = C.INDEX_UNSET; maskingWindowIndex = C.INDEX_UNSET;
...@@ -1188,7 +1191,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1188,7 +1191,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
private void updateAvailableCommands() { private void updateAvailableCommands() {
Commands previousAvailableCommands = availableCommands; Commands previousAvailableCommands = availableCommands;
availableCommands = getAvailableCommands(PERMANENT_AVAILABLE_COMMANDS); availableCommands = getAvailableCommands(permanentAvailableCommands);
if (!availableCommands.equals(previousAvailableCommands)) { if (!availableCommands.equals(previousAvailableCommands)) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_AVAILABLE_COMMANDS_CHANGED, Player.EVENT_AVAILABLE_COMMANDS_CHANGED,
......
...@@ -668,6 +668,17 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -668,6 +668,17 @@ public class SimpleExoPlayer extends BasePlayer
throwsWhenUsingWrongThread = true; throwsWhenUsingWrongThread = true;
// Build the player and associated objects. // Build the player and associated objects.
Commands additionalPermanentAvailableCommands =
new Commands.Builder()
.addAll(
COMMAND_GET_VOLUME,
COMMAND_GET_DEVICE_VOLUME,
COMMAND_SET_VOLUME,
COMMAND_SET_DEVICE_VOLUME,
COMMAND_ADJUST_DEVICE_VOLUME,
COMMAND_SET_VIDEO_SURFACE,
COMMAND_GET_TEXT)
.build();
player = player =
new ExoPlayerImpl( new ExoPlayerImpl(
renderers, renderers,
...@@ -683,7 +694,8 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -683,7 +694,8 @@ public class SimpleExoPlayer extends BasePlayer
builder.pauseAtEndOfMediaItems, builder.pauseAtEndOfMediaItems,
builder.clock, builder.clock,
builder.looper, builder.looper,
/* wrappingPlayer= */ this); /* wrappingPlayer= */ this,
additionalPermanentAvailableCommands);
player.addListener(componentListener); player.addListener(componentListener);
player.addAudioOffloadListener(componentListener); player.addAudioOffloadListener(componentListener);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment