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
This commit is contained in:
tonihei 2020-10-28 12:10:04 +00:00 committed by Oliver Woodman
parent de729ecf3a
commit ae6907e1f5

View File

@ -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);
}
}