[Android] Remember playback state for call interruption

Geoffrey Métais git at videolan.org
Mon Mar 21 16:05:42 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 21 15:47:14 2016 +0100| [f6c59bf0c2b688a9c430c3349b46dd168e960437] | committer: Geoffrey Métais

Remember playback state for call interruption

> https://code.videolan.org/videolan/vlc-android/commit/f6c59bf0c2b688a9c430c3349b46dd168e960437
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 2adc3b1..f9881ef 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -350,6 +350,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         return new OnAudioFocusChangeListener() {
             private boolean mLossTransient = false;
             private boolean mLossTransientCanDuck = false;
+            private boolean wasPlaying = false;
 
             @Override
             public void onAudioFocusChange(int focusChange) {
@@ -361,13 +362,16 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                         Log.i(TAG, "AUDIOFOCUS_LOSS");
                         // Pause playback
                         changeAudioFocus(false);
-                        pause();
+                        if (wasPlaying)
+                            pause();
                         break;
                     case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT");
                         // Pause playback
                         mLossTransient = true;
-                        mMediaPlayer.pause();
+                        wasPlaying = isPlaying();
+                        if (wasPlaying)
+                            pause();
                         break;
                     case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
@@ -383,9 +387,9 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                         if (mLossTransientCanDuck) {
                             mMediaPlayer.setVolume(100);
                             mLossTransientCanDuck = false;
-                        }
-                        if (mLossTransient) {
-                            mMediaPlayer.play();
+                        } else if (mLossTransient) {
+                            if (wasPlaying)
+                                mMediaPlayer.play();
                             mLossTransient = false;
                         }
                         break;



More information about the Android mailing list