From ddf29c92afb8e22011b00446f01d182f9ef5e99e Mon Sep 17 00:00:00 2001 From: Laurent Cremmer Date: Fri, 9 Sep 2016 16:55:33 +0100 Subject: [PATCH] Fixed PlaybackService ignoring result of requestAudiFocus before (re-)starting playback, also fixed issue where getting loss_transient twice would prevent playback from resuming where audio_focus_gain is next received --- .../android/vanilla/PlaybackService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index ceb1d729..bb5c38e5 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -991,7 +991,10 @@ public final class PlaybackService extends Service if (mNotificationMode != NEVER) startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState, mNotificationMode)); - mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); + final int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); + if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + unsetFlag(FLAG_PLAYING); + } mHandler.removeMessages(MSG_ENTER_SLEEP_STATE); try { @@ -2140,9 +2143,10 @@ public final class PlaybackService extends Service case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: synchronized (mStateLock) { - mTransientAudioLoss = (mState & FLAG_PLAYING) != 0; - if(mTransientAudioLoss) { - if (type == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { + if((mState & FLAG_PLAYING) != 0) { + mTransientAudioLoss = true; + + if(type == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { setFlag(FLAG_DUCKING); } else { mForceNotificationVisible = true;