From e28adb00ff500cdc35e3078f8695b0a46aa0e34c Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 30 Nov 2017 05:53:45 -0800 Subject: [PATCH] Use Handler to post action schedule finished callback. Calling it directly might skip other callbacks. For example: ActionSchedule.Builder().waitForTimelineChanged(...).build(). is currently immediately calling through to callback.onActionScheduleFinished when the timeline changes. Depending on the position of the action schedule listener in the listener set, it may skip other listeners also listening to timeline changes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177442975 --- .../exoplayer2/testutil/ActionSchedule.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 7a2ce9270c..477071f91f 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 @@ -41,6 +41,7 @@ import com.google.android.exoplayer2.testutil.Action.WaitForPositionDiscontinuit import com.google.android.exoplayer2.testutil.Action.WaitForSeekProcessed; import com.google.android.exoplayer2.testutil.Action.WaitForTimelineChanged; import com.google.android.exoplayer2.trackselection.MappingTrackSelector; +import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; /** @@ -487,13 +488,30 @@ public final class ActionSchedule { } @Override - protected void doActionImpl(SimpleExoPlayer player, MappingTrackSelector trackSelector, - Surface surface) { + protected void doActionAndScheduleNextImpl( + SimpleExoPlayer player, + MappingTrackSelector trackSelector, + Surface surface, + Handler handler, + ActionNode nextAction) { + Assertions.checkArgument(nextAction == null); if (callback != null) { - callback.onActionScheduleFinished(); + handler.post( + new Runnable() { + @Override + public void run() { + callback.onActionScheduleFinished(); + } + }); } } + @Override + protected void doActionImpl( + SimpleExoPlayer player, MappingTrackSelector trackSelector, Surface surface) { + // Not triggered. + } + } }