diff options
author | ByteHamster <info@bytehamster.com> | 2019-09-10 14:18:14 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-09-10 14:18:14 +0200 |
commit | fe562651147069aa662262d48726d7d96a0c87da (patch) | |
tree | 2dc5339f1f12745caa761228fec49c58ca711c4e | |
parent | 037c4d39222f6cf0f78e1d95d31b8810119e2bd7 (diff) | |
download | AntennaPod-fe562651147069aa662262d48726d7d96a0c87da.zip |
Restart service when re-gaining audio focus
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java | 15 |
1 files changed, 14 insertions, 1 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 3c78a870b..5177fa6be 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 @@ -12,6 +12,7 @@ import android.util.Log; import android.util.Pair; import android.view.SurfaceHolder; +import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import org.antennapod.audio.MediaPlayer; import java.io.File; @@ -705,7 +706,6 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { */ @Override public void shutdown() { - abandonAudioFocus(); executor.shutdown(); if (mediaPlayer != null) { try { @@ -839,6 +839,19 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { @Override public void onAudioFocusChange(final int focusChange) { + if (!PlaybackService.isRunning) { + abandonAudioFocus(); + Log.d(TAG, "onAudioFocusChange: PlaybackService is no longer running"); + if (focusChange == AudioManager.AUDIOFOCUS_GAIN && pausedBecauseOfTransientAudiofocusLoss) { + new PlaybackServiceStarter(context, getPlayable()) + .startWhenPrepared(true) + .streamIfLastWasStream() + .callEvenIfRunning(false) + .start(); + } + return; + } + executor.submit(() -> { playerLock.lock(); |