[Android] [PATCH 2/5] Revert "VideoPlayer: safer changeAudioFocus"

Thomas Guillem thomas at gllm.fr
Tue Mar 17 17:41:40 CET 2015


This reverts commit dabacdf675a62cde497ee13ff8fdcdbfe02458cf.
---
 .../vlc/gui/video/VideoPlayerActivity.java         | 61 +++++++++++-----------
 1 file changed, 31 insertions(+), 30 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 98b9f11..df38e84 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1218,40 +1218,41 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         if(!LibVlcUtil.isFroyoOrLater()) // NOP if not supported
             return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
 
-        mLostFocus = false;
-        int result;
-        if(acquire) {
-            if (mAudioFocusListener != null) {
-                mAudioFocusListener = new OnAudioFocusChangeListener() {
-                    @Override
-                    public void onAudioFocusChange(int focusChange) {
+        if (mAudioFocusListener == null) {
+            mAudioFocusListener = new OnAudioFocusChangeListener() {
+                @Override
+                public void onAudioFocusChange(int focusChange) {
                     /*
                      * Pause playback during alerts and notifications
                      */
-                        switch (focusChange) {
-                            case AudioManager.AUDIOFOCUS_LOSS:
-                            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
-                            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
-                                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() && mLostFocus)
-                                    mLibVLC.play();
-                                mLostFocus = false;
-                                break;
-                        }
+                    switch (focusChange)
+                    {
+                        case AudioManager.AUDIOFOCUS_LOSS:
+                        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
+                        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
+                            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() && mLostFocus)
+                                mLibVLC.play();
+                            mLostFocus = false;
+                            break;
                     }
-                };
-                result = mAudioManager.requestAudioFocus(mAudioFocusListener,
-                        AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
-                mAudioManager.setParameters("bgm_state=true");
-            } else
-                result = AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
+                }
+            };
+        }
+
+        mLostFocus = false;
+        int result;
+        if(acquire) {
+            result = mAudioManager.requestAudioFocus(mAudioFocusListener,
+                    AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
+            mAudioManager.setParameters("bgm_state=true");
         }
         else {
             if (mAudioManager != null && mAudioFocusListener != null) {
-- 
2.1.3



More information about the Android mailing list