diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java index 60cf6d278b..d7853e435f 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java @@ -544,12 +544,16 @@ public abstract class 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 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"); this.expectedTimeline = expectedTimeline; } @@ -564,18 +568,19 @@ public abstract class Action { if (nextAction == null) { return; } - Player.EventListener listener = new Player.DefaultEventListener() { - @Override - public void onTimelineChanged(Timeline timeline, Object manifest, - @Player.TimelineChangeReason int reason) { - if (timeline.equals(expectedTimeline)) { - player.removeListener(this); - nextAction.schedule(player, trackSelector, surface, handler); - } - } - }; + Player.EventListener listener = + new Player.DefaultEventListener() { + @Override + public void onTimelineChanged( + Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) { + if (expectedTimeline == null || timeline.equals(expectedTimeline)) { + player.removeListener(this); + nextAction.schedule(player, trackSelector, surface, handler); + } + } + }; player.addListener(listener); - if (player.getCurrentTimeline().equals(expectedTimeline)) { + if (expectedTimeline != null && player.getCurrentTimeline().equals(expectedTimeline)) { player.removeListener(listener); nextAction.schedule(player, trackSelector, surface, handler); } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java index 2ea8a50a84..841928c932 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java @@ -378,10 +378,11 @@ public final class ActionSchedule { /** * 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. */ - public Builder waitForTimelineChanged(Timeline expectedTimeline) { + public Builder waitForTimelineChanged(@Nullable Timeline expectedTimeline) { return apply(new WaitForTimelineChanged(tag, expectedTimeline)); }