[Android] [PATCH 1/3] fix paused video resumed when a new notification is received

Thomas Guillem thomas at gllm.fr
Mon Mar 16 18:20:04 CET 2015


---
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java      | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 324c79e..9f6e383 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -273,6 +273,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
      * (e.g. lock screen, or to restore the pause state)
      */
     private boolean mPauseOnLoaded = false;
+    private boolean mLostFocus = false;
 
     // Tips
     private View mOverlayTips;
@@ -1201,20 +1202,24 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
                         case AudioManager.AUDIOFOCUS_LOSS:
                         case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                         case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
-                            if (mLibVLC.isPlaying())
+                            if (mLibVLC.isPlaying()) {
                                 mLibVLC.pause();
+                                mLostFocus = true;
+                            }
                             break;
                         case AudioManager.AUDIOFOCUS_GAIN:
                         case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
                         case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
-                            if (!mLibVLC.isPlaying())
+                            if (!mLibVLC.isPlaying() && mLostFocus)
                                 mLibVLC.play();
+                            mLostFocus = false;
                             break;
                     }
                 }
             };
         }
 
+        mLostFocus = false;
         int result;
         if(acquire) {
             result = mAudioManager.requestAudioFocus(mAudioFocusListener,
-- 
2.1.3



More information about the Android mailing list