diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-09-09 22:56:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 22:56:40 +0200 |
commit | 037c4d39222f6cf0f78e1d95d31b8810119e2bd7 (patch) | |
tree | fe434a68e0283c4df932ddca2459af7d08d34756 | |
parent | 60faccb27a175f66dbe2f5e2b02893a912a997e1 (diff) | |
parent | 0d0566e59580feff2d4af33ab3c2993028f69d29 (diff) | |
download | AntennaPod-037c4d39222f6cf0f78e1d95d31b8810119e2bd7.zip |
Merge pull request #3397 from ByteHamster/fix-crash-audio-focus-after-shutdown
Fixed receiving audio events after service shutdown
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java | 27 |
1 files changed, 13 insertions, 14 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 6bd736de7..3c78a870b 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 @@ -350,13 +350,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { setPlayerStatus(PlayerStatus.PAUSED, media, getPosition()); if (abandonFocus) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - AudioFocusRequest.Builder builder = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) - .setOnAudioFocusChangeListener(audioFocusChangeListener); - audioManager.abandonAudioFocusRequest(builder.build()); - } else { - audioManager.abandonAudioFocus(audioFocusChangeListener); - } + abandonAudioFocus(); pausedBecauseOfTransientAudiofocusLoss = false; } if (stream && reinit) { @@ -370,6 +364,16 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { }); } + private void abandonAudioFocus() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AudioFocusRequest.Builder builder = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) + .setOnAudioFocusChangeListener(audioFocusChangeListener); + audioManager.abandonAudioFocusRequest(builder.build()); + } else { + audioManager.abandonAudioFocus(audioFocusChangeListener); + } + } + /** * Prepares media player for playback if the service is in the INITALIZED * state. @@ -701,6 +705,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { */ @Override public void shutdown() { + abandonAudioFocus(); executor.shutdown(); if (mediaPlayer != null) { try { @@ -907,13 +912,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { mediaPlayer.reset(); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - AudioFocusRequest.Builder builder = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) - .setOnAudioFocusChangeListener(audioFocusChangeListener); - audioManager.abandonAudioFocusRequest(builder.build()); - } else { - audioManager.abandonAudioFocus(audioFocusChangeListener); - } + abandonAudioFocus(); final Playable currentMedia = media; Playable nextMedia = null; |