From 5a9958098564a38513ace68aac92c235aab3d65e Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 7 May 2019 15:21:54 +0200 Subject: [PATCH] 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. --- .../core/service/playback/LocalPSMP.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 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 d0ad45f1c..a4099bf94 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 @@ -1088,25 +1088,17 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { mp -> genericSeekCompleteListener(); private void genericSeekCompleteListener() { - Runnable r = () -> { - Log.d(TAG, "genericSeekCompleteListener"); - if(seekLatch != null) { - 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); + Log.d(TAG, "genericSeekCompleteListener"); + if (seekLatch != null) { + seekLatch.countDown(); } + playerLock.lock(); + if (playerStatus == PlayerStatus.PLAYING) { + callback.onPlaybackStart(media, getPosition()); + } + if (playerStatus == PlayerStatus.SEEKING) { + setPlayerStatus(statusBeforeSeeking, media, getPosition()); + } + playerLock.unlock(); } }