Commit 7e7fea40 by tonihei Committed by Oliver Woodman

Add WaitForPlaybackStateChanged action to action schedule.

This works similar to the existing WaitForXXXX actions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170687058
parent fd576d21
......@@ -380,6 +380,49 @@ public abstract class Action {
}
/**
* Waits for a specified playback state, returning either immediately or after a call to
* {@link Player.EventListener#onPlayerStateChanged(boolean, int)}.
*/
public static final class WaitForPlaybackState extends Action {
private final int targetPlaybackState;
/**
* @param tag A tag to use for logging.
*/
public WaitForPlaybackState(String tag, int targetPlaybackState) {
super(tag, "WaitForPlaybackState");
this.targetPlaybackState = targetPlaybackState;
}
@Override
protected void doActionAndScheduleNextImpl(final SimpleExoPlayer player,
final MappingTrackSelector trackSelector, final Surface surface, final Handler handler,
final ActionNode nextAction) {
if (targetPlaybackState == player.getPlaybackState()) {
nextAction.schedule(player, trackSelector, surface, handler);
} else {
player.addListener(new Player.DefaultEventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (targetPlaybackState == playbackState) {
player.removeListener(this);
nextAction.schedule(player, trackSelector, surface, handler);
}
}
});
}
}
@Override
protected void doActionImpl(SimpleExoPlayer player, MappingTrackSelector trackSelector,
Surface surface) {
// Not triggered.
}
}
/**
* Calls {@link Runnable#run()}.
*/
public static final class ExecuteRunnable extends Action {
......
......@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.testutil.Action.SetRepeatMode;
import com.google.android.exoplayer2.testutil.Action.SetShuffleModeEnabled;
import com.google.android.exoplayer2.testutil.Action.SetVideoSurface;
import com.google.android.exoplayer2.testutil.Action.Stop;
import com.google.android.exoplayer2.testutil.Action.WaitForPlaybackState;
import com.google.android.exoplayer2.testutil.Action.WaitForPositionDiscontinuity;
import com.google.android.exoplayer2.testutil.Action.WaitForTimelineChanged;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
......@@ -258,6 +259,16 @@ public final class ActionSchedule {
}
/**
* Schedules a delay until the playback state changed to the specified state.
*
* @param targetPlaybackState The target playback state.
* @return The builder, for convenience.
*/
public Builder waitForPlaybackState(int targetPlaybackState) {
return apply(new WaitForPlaybackState(tag, targetPlaybackState));
}
/**
* Schedules a {@link Runnable} to be executed.
*
* @return The builder, for convenience.
......
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