[Android] Remember playback state for headset detection

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


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

Remember playback state for headset detection

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

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 63ffc39..2adc3b1 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -442,6 +442,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     } : null;
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        private boolean wasPlaying = false;
         @Override
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
@@ -505,11 +506,12 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             else if (mDetectHeadset && !mHasHdmiAudio) {
                 if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
                     Log.i(TAG, "Headset Removed.");
-                    if (hasCurrentMedia())
+                    wasPlaying = isPlaying();
+                    if (wasPlaying && hasCurrentMedia())
                         pause();
                 } else if (action.equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG) && state != 0) {
                     Log.i(TAG, "Headset Inserted.");
-                    if (hasCurrentMedia())
+                    if (wasPlaying && hasCurrentMedia())
                         play();
                 }
             }



More information about the Android mailing list