Add test action to wait for an isLoading change.

This allows to wait until loading started or finished.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215704424
This commit is contained in:
tonihei 2018-10-04 02:07:17 -07:00 committed by Oliver Woodman
parent 9ca6544311
commit 711f9f8b6a
2 changed files with 61 additions and 0 deletions

View File

@ -686,6 +686,56 @@ public abstract class Action {
}
}
/**
* Waits for a specified loading state, returning either immediately or after a call to {@link
* Player.EventListener#onLoadingChanged(boolean)}.
*/
public static final class WaitForIsLoading extends Action {
private final boolean targetIsLoading;
/**
* @param tag A tag to use for logging.
* @param targetIsLoading The loading state to wait for.
*/
public WaitForIsLoading(String tag, boolean targetIsLoading) {
super(tag, "WaitForIsLoading");
this.targetIsLoading = targetIsLoading;
}
@Override
protected void doActionAndScheduleNextImpl(
final SimpleExoPlayer player,
final DefaultTrackSelector trackSelector,
final Surface surface,
final HandlerWrapper handler,
final ActionNode nextAction) {
if (nextAction == null) {
return;
}
if (targetIsLoading == player.isLoading()) {
nextAction.schedule(player, trackSelector, surface, handler);
} else {
player.addListener(
new Player.EventListener() {
@Override
public void onLoadingChanged(boolean isLoading) {
if (targetIsLoading == isLoading) {
player.removeListener(this);
nextAction.schedule(player, trackSelector, surface, handler);
}
}
});
}
}
@Override
protected void doActionImpl(
SimpleExoPlayer player, DefaultTrackSelector trackSelector, Surface surface) {
// Not triggered.
}
}
/**
* Waits for {@link Player.EventListener#onSeekProcessed()}.
*/

View File

@ -41,6 +41,7 @@ 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.ThrowPlaybackException;
import com.google.android.exoplayer2.testutil.Action.WaitForIsLoading;
import com.google.android.exoplayer2.testutil.Action.WaitForPlaybackState;
import com.google.android.exoplayer2.testutil.Action.WaitForPositionDiscontinuity;
import com.google.android.exoplayer2.testutil.Action.WaitForSeekProcessed;
@ -414,6 +415,16 @@ public final class ActionSchedule {
return apply(new WaitForPlaybackState(tag, targetPlaybackState));
}
/**
* Schedules a delay until {@code player.isLoading()} changes to the specified value.
*
* @param targetIsLoading The target value of {@code player.isLoading()}.
* @return The builder, for convenience.
*/
public Builder waitForIsLoading(boolean targetIsLoading) {
return apply(new WaitForIsLoading(tag, targetIsLoading));
}
/**
* Schedules a {@link Runnable} to be executed.
*