[Android] Restore correct audio volume after notifications

Geoffrey Métais git at videolan.org
Fri May 20 16:30:55 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 20 12:11:22 2016 +0200| [2ae42cb85835afd0c5f8a800e522a87901668d0b] | committer: Geoffrey Métais

Restore correct audio volume after notifications

> https://code.videolan.org/videolan/vlc-android/commit/2ae42cb85835afd0c5f8a800e522a87901668d0b
---

 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 6711531..32c7a4d 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -352,7 +352,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,15 +380,15 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                         // Lower the volume
                         if (mMediaPlayer.isPlaying()) {
                             mMediaPlayer.setVolume(36);
-                            mLossTransientCanDuck = true;
+                            mLossTransientVolume = mMediaPlayer.getVolume();
                         }
                         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