[Android] Restore correct audio volume after notifications

Geoffrey Métais git at videolan.org
Sun Jun 5 13:16:18 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sun Jun  5 13:12:56 2016 +0200| [1ec3f021368e399768036e2064e177f6fc6df52d] | committer: Geoffrey Métais

Restore correct audio volume after notifications

> https://code.videolan.org/videolan/vlc-android/commit/1ec3f021368e399768036e2064e177f6fc6df52d
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index f2b919b..975c579 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -353,7 +353,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     private OnAudioFocusChangeListener createOnAudioFocusChangeListener() {
         return new OnAudioFocusChangeListener() {
             private boolean mLossTransient = false;
-            private boolean mLossTransientCanDuck = false;
+            private int mLossTransientVolume = -1;
             private boolean wasPlaying = false;
 
             @Override
@@ -380,16 +380,16 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
                         // Lower the volume
                         if (mMediaPlayer.isPlaying()) {
+                            mLossTransientVolume = mMediaPlayer.getVolume();
                             mMediaPlayer.setVolume(36);
-                            mLossTransientCanDuck = true;
                         }
                         break;
                     case AudioManager.AUDIOFOCUS_GAIN:
-                        Log.i(TAG, "AUDIOFOCUS_GAIN: " + mLossTransientCanDuck + ", " + mLossTransient);
+                        Log.i(TAG, "AUDIOFOCUS_GAIN: " + mLossTransientVolume + ", " + mLossTransient);
                         // Resume playback
-                        if (mLossTransientCanDuck) {
-                            mMediaPlayer.setVolume(100);
-                            mLossTransientCanDuck = false;
+                        if (mLossTransientVolume != -1) {
+                            mMediaPlayer.setVolume(mLossTransientVolume);
+                            mLossTransientVolume = -1;
                         } else if (mLossTransient) {
                             if (wasPlaying)
                                 mMediaPlayer.play();



More information about the Android mailing list