Do not deadlock

The Android internal media player blocks its `start()` call until the
seek listener completes. The seek listener is called on the main thread
even though `start()` is called on the executor. This makes the main
thread wait for the lock and the executor (which has the lock) wait for the
main thread to finish the call to the listener.
This commit is contained in:
ByteHamster 2019-05-08 18:54:21 +02:00
parent e464569712
commit bf6f6376db
1 changed files with 16 additions and 7 deletions

View File

@ -1092,13 +1092,22 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
if (seekLatch != null) {
seekLatch.countDown();
}
playerLock.lock();
if (playerStatus == PlayerStatus.PLAYING) {
callback.onPlaybackStart(media, getPosition());
Runnable r = () -> {
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);
}
if (playerStatus == PlayerStatus.SEEKING) {
setPlayerStatus(statusBeforeSeeking, media, getPosition());
}
playerLock.unlock();
}
}