Skip to content

Commit

Permalink
Remove race condition when stopping FakeExoPlayer.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tonihei authored and ojw28 committed Dec 12, 2017
1 parent 6c1f562 commit 86d91a5
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,13 @@ public PlaybackParameters getPlaybackParameters() {

@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();
Expand Down Expand Up @@ -525,6 +511,20 @@ private void releaseMedia() {
}
}

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

}

}

0 comments on commit 86d91a5

Please sign in to comment.