Remove race condition when stopping FakeExoPlayer.

A message to stop the playback and to quit the playback thread was posted in release().
The stop message removed all other already queued messages which might include
the second message to quit the thread. That led to infinite waiting in the
release method because the playback thread never got the quit signal.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176997104
This commit is contained in:
tonihei 2017-11-27 03:45:24 -08:00 committed by Oliver Woodman
parent 6c1f562230
commit 86d91a59a0

View file

@ -166,27 +166,13 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
@Override
public void stop() {
playbackHandler.post(new Runnable() {
@Override
public void run () {
playbackHandler.removeCallbacksAndMessages(null);
releaseMedia();
changePlaybackState(Player.STATE_IDLE);
}
});
stop(/* quitPlaybackThread= */ false);
}
@Override
@SuppressWarnings("ThreadJoinLoop")
public void release() {
stop();
playbackHandler.post(new Runnable() {
@Override
public void run () {
playbackHandler.removeCallbacksAndMessages(null);
playbackThread.quit();
}
});
stop(/* quitPlaybackThread= */ true);
while (playbackThread.isAlive()) {
try {
playbackThread.join();
@ -525,6 +511,20 @@ public class FakeSimpleExoPlayer extends SimpleExoPlayer {
}
}
private void stop(boolean quitPlaybackThread) {
playbackHandler.post(new Runnable() {
@Override
public void run () {
playbackHandler.removeCallbacksAndMessages(null);
releaseMedia();
changePlaybackState(Player.STATE_IDLE);
if (quitPlaybackThread) {
playbackThread.quit();
}
}
});
}
}
}