Commit 46c6f260 by olly Committed by Oliver Woodman

Add test action for setting audio attributes

Also removed "to be executed" from all the comments, since it
didn't seem to add value.

PiperOrigin-RevId: 274139837
parent 3f7c3bb0
...@@ -729,7 +729,7 @@ public interface Player { ...@@ -729,7 +729,7 @@ public interface Player {
/** /**
* Sets the {@link RepeatMode} to be used for playback. * Sets the {@link RepeatMode} to be used for playback.
* *
* @param repeatMode A repeat mode. * @param repeatMode The repeat mode.
*/ */
void setRepeatMode(@RepeatMode int repeatMode); void setRepeatMode(@RepeatMode int repeatMode);
......
...@@ -29,6 +29,7 @@ import com.google.android.exoplayer2.PlayerMessage; ...@@ -29,6 +29,7 @@ import com.google.android.exoplayer2.PlayerMessage;
import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.PlayerMessage.Target;
import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.testutil.ActionSchedule.ActionNode; import com.google.android.exoplayer2.testutil.ActionSchedule.ActionNode;
import com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable; import com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable;
...@@ -290,6 +291,31 @@ public abstract class Action { ...@@ -290,6 +291,31 @@ public abstract class Action {
} }
} }
/** Calls {@link SimpleExoPlayer#setAudioAttributes(AudioAttributes, boolean)}. */
public static final class SetAudioAttributes extends Action {
private final AudioAttributes audioAttributes;
private final boolean handleAudioFocus;
/**
* @param tag A tag to use for logging.
* @param audioAttributes The attributes to use for audio playback.
* @param handleAudioFocus True if the player should handle audio focus, false otherwise.
*/
public SetAudioAttributes(
String tag, AudioAttributes audioAttributes, boolean handleAudioFocus) {
super(tag, "SetAudioAttributes");
this.audioAttributes = audioAttributes;
this.handleAudioFocus = handleAudioFocus;
}
@Override
protected void doActionImpl(
SimpleExoPlayer player, DefaultTrackSelector trackSelector, Surface surface) {
player.setAudioAttributes(audioAttributes, handleAudioFocus);
}
}
/** Calls {@link ExoPlayer#prepare(MediaSource)}. */ /** Calls {@link ExoPlayer#prepare(MediaSource)}. */
public static final class PrepareSource extends Action { public static final class PrepareSource extends Action {
...@@ -297,12 +323,19 @@ public abstract class Action { ...@@ -297,12 +323,19 @@ public abstract class Action {
private final boolean resetPosition; private final boolean resetPosition;
private final boolean resetState; private final boolean resetState;
/** @param tag A tag to use for logging. */ /**
* @param tag A tag to use for logging.
* @param mediaSource The {@link MediaSource} to prepare the player with.
*/
public PrepareSource(String tag, MediaSource mediaSource) { public PrepareSource(String tag, MediaSource mediaSource) {
this(tag, mediaSource, true, true); this(tag, mediaSource, true, true);
} }
/** @param tag A tag to use for logging. */ /**
* @param tag A tag to use for logging.
* @param mediaSource The {@link MediaSource} to prepare the player with.
* @param resetPosition Whether the player's position should be reset.
*/
public PrepareSource( public PrepareSource(
String tag, MediaSource mediaSource, boolean resetPosition, boolean resetState) { String tag, MediaSource mediaSource, boolean resetPosition, boolean resetState) {
super(tag, "PrepareSource"); super(tag, "PrepareSource");
...@@ -323,7 +356,10 @@ public abstract class Action { ...@@ -323,7 +356,10 @@ public abstract class Action {
private final @Player.RepeatMode int repeatMode; private final @Player.RepeatMode int repeatMode;
/** @param tag A tag to use for logging. */ /**
* @param tag A tag to use for logging.
* @param repeatMode The repeat mode.
*/
public SetRepeatMode(String tag, @Player.RepeatMode int repeatMode) { public SetRepeatMode(String tag, @Player.RepeatMode int repeatMode) {
super(tag, "SetRepeatMode:" + repeatMode); super(tag, "SetRepeatMode:" + repeatMode);
this.repeatMode = repeatMode; this.repeatMode = repeatMode;
...@@ -341,7 +377,10 @@ public abstract class Action { ...@@ -341,7 +377,10 @@ public abstract class Action {
private final boolean shuffleModeEnabled; private final boolean shuffleModeEnabled;
/** @param tag A tag to use for logging. */ /**
* @param tag A tag to use for logging.
* @param shuffleModeEnabled Whether shuffling is enabled.
*/
public SetShuffleModeEnabled(String tag, boolean shuffleModeEnabled) { public SetShuffleModeEnabled(String tag, boolean shuffleModeEnabled) {
super(tag, "SetShuffleModeEnabled:" + shuffleModeEnabled); super(tag, "SetShuffleModeEnabled:" + shuffleModeEnabled);
this.shuffleModeEnabled = shuffleModeEnabled; this.shuffleModeEnabled = shuffleModeEnabled;
......
...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.PlayerMessage; ...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.PlayerMessage;
import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.PlayerMessage.Target;
import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.testutil.Action.ClearVideoSurface; import com.google.android.exoplayer2.testutil.Action.ClearVideoSurface;
import com.google.android.exoplayer2.testutil.Action.ExecuteRunnable; import com.google.android.exoplayer2.testutil.Action.ExecuteRunnable;
...@@ -35,6 +36,7 @@ import com.google.android.exoplayer2.testutil.Action.PrepareSource; ...@@ -35,6 +36,7 @@ import com.google.android.exoplayer2.testutil.Action.PrepareSource;
import com.google.android.exoplayer2.testutil.Action.Seek; import com.google.android.exoplayer2.testutil.Action.Seek;
import com.google.android.exoplayer2.testutil.Action.SendBroadcast; import com.google.android.exoplayer2.testutil.Action.SendBroadcast;
import com.google.android.exoplayer2.testutil.Action.SendMessages; import com.google.android.exoplayer2.testutil.Action.SendMessages;
import com.google.android.exoplayer2.testutil.Action.SetAudioAttributes;
import com.google.android.exoplayer2.testutil.Action.SetPlayWhenReady; import com.google.android.exoplayer2.testutil.Action.SetPlayWhenReady;
import com.google.android.exoplayer2.testutil.Action.SetPlaybackParameters; import com.google.android.exoplayer2.testutil.Action.SetPlaybackParameters;
import com.google.android.exoplayer2.testutil.Action.SetRendererDisabled; import com.google.android.exoplayer2.testutil.Action.SetRendererDisabled;
...@@ -133,7 +135,7 @@ public final class ActionSchedule { ...@@ -133,7 +135,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules an action to be executed. * Schedules an action.
* *
* @param action The action to schedule. * @param action The action to schedule.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -143,7 +145,7 @@ public final class ActionSchedule { ...@@ -143,7 +145,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules an action to be executed repeatedly. * Schedules an action repeatedly.
* *
* @param action The action to schedule. * @param action The action to schedule.
* @param intervalMs The interval between each repetition in milliseconds. * @param intervalMs The interval between each repetition in milliseconds.
...@@ -154,7 +156,7 @@ public final class ActionSchedule { ...@@ -154,7 +156,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a seek action to be executed. * Schedules a seek action.
* *
* @param positionMs The seek position. * @param positionMs The seek position.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -164,7 +166,7 @@ public final class ActionSchedule { ...@@ -164,7 +166,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a seek action to be executed. * Schedules a seek action.
* *
* @param windowIndex The window to seek to. * @param windowIndex The window to seek to.
* @param positionMs The seek position. * @param positionMs The seek position.
...@@ -175,7 +177,7 @@ public final class ActionSchedule { ...@@ -175,7 +177,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a seek action to be executed and waits until playback resumes after the seek. * Schedules a seek action and waits until playback resumes after the seek.
* *
* @param positionMs The seek position. * @param positionMs The seek position.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -196,7 +198,7 @@ public final class ActionSchedule { ...@@ -196,7 +198,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a playback parameters setting action to be executed. * Schedules a playback parameters setting action.
* *
* @param playbackParameters The playback parameters to set. * @param playbackParameters The playback parameters to set.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -207,7 +209,7 @@ public final class ActionSchedule { ...@@ -207,7 +209,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a stop action to be executed. * Schedules a stop action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -216,7 +218,7 @@ public final class ActionSchedule { ...@@ -216,7 +218,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a stop action to be executed. * Schedules a stop action.
* *
* @param reset Whether the player should be reset. * @param reset Whether the player should be reset.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -226,7 +228,7 @@ public final class ActionSchedule { ...@@ -226,7 +228,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a play action to be executed. * Schedules a play action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -235,8 +237,8 @@ public final class ActionSchedule { ...@@ -235,8 +237,8 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a play action to be executed, waits until the player reaches the specified * Schedules a play action, waits until the player reaches the specified position, and pauses
* position, and pauses the player again. * the player again.
* *
* @param windowIndex The window index at which the player should be paused again. * @param windowIndex The window index at which the player should be paused again.
* @param positionMs The position in that window at which the player should be paused again. * @param positionMs The position in that window at which the player should be paused again.
...@@ -247,8 +249,8 @@ public final class ActionSchedule { ...@@ -247,8 +249,8 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a play action to be executed, waits until the player reaches the start of the * Schedules a play action, waits until the player reaches the start of the specified window,
* specified window, and pauses the player again. * and pauses the player again.
* *
* @param windowIndex The window index at which the player should be paused again. * @param windowIndex The window index at which the player should be paused again.
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -258,7 +260,7 @@ public final class ActionSchedule { ...@@ -258,7 +260,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a pause action to be executed. * Schedules a pause action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -267,7 +269,7 @@ public final class ActionSchedule { ...@@ -267,7 +269,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a renderer enable action to be executed. * Schedules a renderer enable action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -276,7 +278,7 @@ public final class ActionSchedule { ...@@ -276,7 +278,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a renderer disable action to be executed. * Schedules a renderer disable action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -285,7 +287,7 @@ public final class ActionSchedule { ...@@ -285,7 +287,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a clear video surface action to be executed. * Schedules a clear video surface action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -294,7 +296,7 @@ public final class ActionSchedule { ...@@ -294,7 +296,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a set video surface action to be executed. * Schedules a set video surface action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -303,7 +305,16 @@ public final class ActionSchedule { ...@@ -303,7 +305,16 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a new source preparation action to be executed. * Schedules application of audio attributes.
*
* @return The builder, for convenience.
*/
public Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) {
return apply(new SetAudioAttributes(tag, audioAttributes, handleAudioFocus));
}
/**
* Schedules a new source preparation action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -312,7 +323,7 @@ public final class ActionSchedule { ...@@ -312,7 +323,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a new source preparation action to be executed. * Schedules a new source preparation action.
* *
* @see com.google.android.exoplayer2.ExoPlayer#prepare(MediaSource, boolean, boolean) * @see com.google.android.exoplayer2.ExoPlayer#prepare(MediaSource, boolean, boolean)
* @return The builder, for convenience. * @return The builder, for convenience.
...@@ -323,7 +334,7 @@ public final class ActionSchedule { ...@@ -323,7 +334,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a repeat mode setting action to be executed. * Schedules a repeat mode setting action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -332,7 +343,7 @@ public final class ActionSchedule { ...@@ -332,7 +343,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a shuffle setting action to be executed. * Schedules a shuffle setting action.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -438,7 +449,7 @@ public final class ActionSchedule { ...@@ -438,7 +449,7 @@ public final class ActionSchedule {
} }
/** /**
* Schedules a {@link Runnable} to be executed. * Schedules a {@link Runnable}.
* *
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
...@@ -560,8 +571,8 @@ public final class ActionSchedule { ...@@ -560,8 +571,8 @@ public final class ActionSchedule {
} }
/** /**
* Schedules {@link #action} to be executed after {@link #delayMs}. The {@link #next} node will * Schedules {@link #action} after {@link #delayMs}. The {@link #next} node will be scheduled
* be scheduled immediately after {@link #action} is executed. * immediately after {@link #action} is executed.
* *
* @param player The player to which actions should be applied. * @param player The player to which actions should be applied.
* @param trackSelector The track selector to which actions should be applied. * @param trackSelector The track selector to which actions should be applied.
......
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