Do not deadlock on seek when using Sonic

Callbacks are called on the thread that created the MediaPlayer.
For Sonic, this is the executor. For ExoPlayer, this is the main thread.
When calling executor.submit, every thread waiting for the runnable to
complete gets blocked.

Because the callback is called in the thread that created the player,
we can simply remove the call to executor.submit and still be sure
that a background thread is used.
This commit is contained in:
ByteHamster 2019-05-07 15:21:54 +02:00
parent c16bbdfc96
commit 5a99580985
1 changed files with 11 additions and 19 deletions

View File

@ -1088,25 +1088,17 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
mp -> genericSeekCompleteListener(); mp -> genericSeekCompleteListener();
private void genericSeekCompleteListener() { private void genericSeekCompleteListener() {
Runnable r = () -> { Log.d(TAG, "genericSeekCompleteListener");
Log.d(TAG, "genericSeekCompleteListener"); if (seekLatch != null) {
if(seekLatch != null) { seekLatch.countDown();
seekLatch.countDown();
}
playerLock.lock();
if (playerStatus == PlayerStatus.PLAYING) {
callback.onPlaybackStart(media, getPosition());
}
if (playerStatus == PlayerStatus.SEEKING) {
setPlayerStatus(statusBeforeSeeking, media, getPosition());
}
playerLock.unlock();
};
if (useCallerThread) {
r.run();
} else {
executor.submit(r);
} }
playerLock.lock();
if (playerStatus == PlayerStatus.PLAYING) {
callback.onPlaybackStart(media, getPosition());
}
if (playerStatus == PlayerStatus.SEEKING) {
setPlayerStatus(statusBeforeSeeking, media, getPosition());
}
playerLock.unlock();
} }
} }