[Android] Reinstate compatibility with Android-7 !

Jean-Baptiste Kempf git at videolan.org
Sun Oct 7 00:53:12 CEST 2012


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Oct  7 00:51:46 2012 +0200| [693e128800c55405aa3b220082c82bdc31f93368] | committer: Jean-Baptiste Kempf

Reinstate compatibility with Android-7 !

Tested on Xperia X10, thanks to Nolvenn

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

 vlc-android/src/org/videolan/vlc/AudioService.java |   48 ++++++++++----------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 294a68d..f41e20d 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -92,6 +92,7 @@ public class AudioService extends Service {
     private boolean mDetectHeadset = true;
     private long mHeadsetDownTime = 0;
     private long mHeadsetUpTime = 0;
+    private OnAudioFocusChangeListener audioFocusListener;
 
     /**
      * RemoteControlClient is for lock screen playback control.
@@ -201,35 +202,36 @@ public class AudioService extends Service {
         if(!Util.isGingerbreadOrLater()) // NOP if not supported
             return;
 
+        audioFocusListener = new OnAudioFocusChangeListener() {
+            int volume = -1;
+            @Override
+            public void onAudioFocusChange(int focusChange) {
+                AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
+                if(focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK ||
+                   focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
+                    volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
+                    int maxVol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
+                    /*
+                     * Lower the volume to 19% to "duck" when an alert or something
+                     * needs to be played.
+                     */
+                    am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(0.19*maxVol), 0);
+                } else {
+                    if(volume != -1) {
+                        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
+                        volume = -1;
+                    }
+                }
+            }
+        };
+
         AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
         if(gain)
             am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
         else
             am.abandonAudioFocus(audioFocusListener);
-    }
 
-    private final OnAudioFocusChangeListener audioFocusListener = new OnAudioFocusChangeListener() {
-        int volume = -1;
-        @Override
-        public void onAudioFocusChange(int focusChange) {
-            AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
-            if(focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK ||
-               focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
-                volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
-                int maxVol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
-                /*
-                 * Lower the volume to 19% to "duck" when an alert or something
-                 * needs to be played.
-                 */
-                am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(0.19*maxVol), 0);
-            } else {
-                if(volume != -1) {
-                    am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
-                    volume = -1;
-                }
-            }
-        }
-    };
+    }
 
     private final BroadcastReceiver serviceReceiver = new BroadcastReceiver() {
         @Override



More information about the Android mailing list