[Android] Revert "VideoPlayer: safer changeAudioFocus"

Thomas Guillem git at videolan.org
Tue Mar 17 18:06:27 CET 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Mar 17 14:19:19 2015 +0100| [53fba2a4827123dfe64d4546eaa1d35376a885d2] | committer: Thomas Guillem

Revert "VideoPlayer: safer changeAudioFocus"

This reverts commit dabacdf675a62cde497ee13ff8fdcdbfe02458cf.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=53fba2a4827123dfe64d4546eaa1d35376a885d2
---

 .../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) {



More information about the Android mailing list