Commit a71a87af by tonihei Committed by Oliver Woodman

Amend WaitForTimelineChange action to allow waiting for arbitrary timeline.

In some situations, the timeline can't be specified because it is created
internally by the media source under test. If the test still needs to wait for
a timeline update, this change allows to do that by specifying an expected
timeline of null.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190768386
parent e2289478
...@@ -544,12 +544,16 @@ public abstract class Action { ...@@ -544,12 +544,16 @@ public abstract class Action {
*/ */
public static final class WaitForTimelineChanged extends Action { public static final class WaitForTimelineChanged extends Action {
private final Timeline expectedTimeline; private final @Nullable Timeline expectedTimeline;
/** /**
* Creates action waiting for a timeline change.
*
* @param tag A tag to use for logging. * @param tag A tag to use for logging.
* @param expectedTimeline The expected timeline to wait for. If null, wait for any timeline
* change.
*/ */
public WaitForTimelineChanged(String tag, Timeline expectedTimeline) { public WaitForTimelineChanged(String tag, @Nullable Timeline expectedTimeline) {
super(tag, "WaitForTimelineChanged"); super(tag, "WaitForTimelineChanged");
this.expectedTimeline = expectedTimeline; this.expectedTimeline = expectedTimeline;
} }
...@@ -564,18 +568,19 @@ public abstract class Action { ...@@ -564,18 +568,19 @@ public abstract class Action {
if (nextAction == null) { if (nextAction == null) {
return; return;
} }
Player.EventListener listener = new Player.DefaultEventListener() { Player.EventListener listener =
@Override new Player.DefaultEventListener() {
public void onTimelineChanged(Timeline timeline, Object manifest, @Override
@Player.TimelineChangeReason int reason) { public void onTimelineChanged(
if (timeline.equals(expectedTimeline)) { Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) {
player.removeListener(this); if (expectedTimeline == null || timeline.equals(expectedTimeline)) {
nextAction.schedule(player, trackSelector, surface, handler); player.removeListener(this);
} nextAction.schedule(player, trackSelector, surface, handler);
} }
}; }
};
player.addListener(listener); player.addListener(listener);
if (player.getCurrentTimeline().equals(expectedTimeline)) { if (expectedTimeline != null && player.getCurrentTimeline().equals(expectedTimeline)) {
player.removeListener(listener); player.removeListener(listener);
nextAction.schedule(player, trackSelector, surface, handler); nextAction.schedule(player, trackSelector, surface, handler);
} }
......
...@@ -378,10 +378,11 @@ public final class ActionSchedule { ...@@ -378,10 +378,11 @@ public final class ActionSchedule {
/** /**
* Schedules a delay until the timeline changed to a specified expected timeline. * Schedules a delay until the timeline changed to a specified expected timeline.
* *
* @param expectedTimeline The expected timeline to wait for. * @param expectedTimeline The expected timeline to wait for. If null, wait for any timeline
* change.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder waitForTimelineChanged(Timeline expectedTimeline) { public Builder waitForTimelineChanged(@Nullable Timeline expectedTimeline) {
return apply(new WaitForTimelineChanged(tag, expectedTimeline)); return apply(new WaitForTimelineChanged(tag, expectedTimeline));
} }
......
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