mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-27 01:03:15 +01:00
Merge pull request #3397 from ByteHamster/fix-crash-audio-focus-after-shutdown
Fixed receiving audio events after service shutdown
This commit is contained in:
commit
037c4d3922
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user