Commit ae6907e1 by tonihei Committed by Oliver Woodman

Don't rely on events after player release in ExoHostedTest

ExoHostedTest was calculating the total play time by solely listening
to onIsPlayingChanged. The last update to false (when playback ends) was relying
on a callback that was always called after the player has already been released.
This happened because of a now fixed bug where callbacks were still issued if
player.release() is called from within another callback (as in ExoHostedTest).

Fix the currently broken test by posting the release call so that all pending
events are still delivered first.

PiperOrigin-RevId: 339438863
parent de729ecf
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.testutil;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import static com.google.common.truth.Truth.assertWithMessage;
import android.os.ConditionVariable;
......@@ -184,7 +185,9 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
playerWasPrepared |= playbackState != Player.STATE_IDLE;
if (playbackState == Player.STATE_ENDED
|| (playbackState == Player.STATE_IDLE && playerWasPrepared)) {
stopTest();
// Post stopTest to ensure all currently pending events (e.g. onIsPlayingChanged or
// onPlayerError) are still delivered before the player is released.
checkStateNotNull(actionHandler).post(this::stopTest);
}
}
......
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