From fe562651147069aa662262d48726d7d96a0c87da Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 10 Sep 2019 14:18:14 +0200 Subject: Restart service when re-gaining audio focus --- .../antennapod/core/service/playback/LocalPSMP.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'core/src/main/java') 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(); -- cgit v1.2.3