mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +00:00
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:
parent
6c1f562230
commit
86d91a59a0
1 changed files with 16 additions and 16 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue