[Android] AudioService: duck the volume properly

Edward Wang git at videolan.org
Fri Nov 23 05:44:21 CET 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Nov 22 23:44:03 2012 -0500| [2a6b679ad5e9cb8c81275d4fa86abda9dcf38119] | committer: Edward Wang

AudioService: duck the volume properly

Close #7644

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

 vlc-android/src/org/videolan/vlc/AudioService.java |   13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 0968c6b..c1894d9 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -235,24 +235,17 @@ public class AudioService extends Service {
             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
+                     * Lower the volume to 36% to "duck" when an alert or something
                      * needs to be played.
                      */
-                    am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(0.19*maxVol), 0);
+                    LibVLC.getExistingInstance().setVolume(36);
                 } else {
-                    if(volume != -1) {
-                        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
-                        volume = -1;
-                    }
+                    LibVLC.getExistingInstance().setVolume(100);
                 }
             }
         };



More information about the Android mailing list