summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-05-08 18:54:21 +0200
committerByteHamster <info@bytehamster.com>2019-05-08 19:18:44 +0200
commitbf6f6376db65a98cfcbcc30ebdca1178404905a9 (patch)
treedcda695460b2b62fa29566e633351db5dbda3085
parente464569712506e0bae1a0150898f4c164a3f1cb3 (diff)
downloadAntennaPod-bf6f6376db65a98cfcbcc30ebdca1178404905a9.zip
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.
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
index a4099bf94..7988526d9 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
@@ -1092,13 +1092,22 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
if (seekLatch != null) {
seekLatch.countDown();
}
- playerLock.lock();
- if (playerStatus == PlayerStatus.PLAYING) {
- callback.onPlaybackStart(media, getPosition());
- }
- if (playerStatus == PlayerStatus.SEEKING) {
- setPlayerStatus(statusBeforeSeeking, 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);
}
- playerLock.unlock();
}
}