Commit 86d91a59 by tonihei Committed by Oliver Woodman

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
parent 6c1f5622
......@@ -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();
}
}
});
}
}
}
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