[Android] Refine audio duck policy

Geoffrey Métais git at videolan.org
Wed Nov 22 16:08:30 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 17 11:40:10 2017 +0100| [6395e16bfc01864b0e71a820d77fb5bab64640af] | committer: Geoffrey Métais

Refine audio duck policy

> https://code.videolan.org/videolan/vlc-android/commit/6395e16bfc01864b0e71a820d77fb5bab64640af
---

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 57a92ddb0..931554b9a 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -413,15 +413,20 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
                         // Lower the volume
                         if (isPlaying()) {
-                            if (AndroidDevices.isAndroidTv) {
+                            if (AndroidDevices.isAmazon) {
                                 pausePlayback();
                             } else {
-                                final int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+                                final int volume = AndroidDevices.isAndroidTv ? getVolume()
+                                        : mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
                                 if (audioDuckLevel == -1)
-                                    audioDuckLevel = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)/5;
+                                    audioDuckLevel = AndroidDevices.isAndroidTv ? 50
+                                            : mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)/5;
                                 if (volume > audioDuckLevel) {
                                     mLossTransientVolume = volume;
-                                    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
+                                    if (AndroidDevices.isAndroidTv)
+                                        setVolume(audioDuckLevel);
+                                    else
+                                        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
                                 }
                             }
                         }
@@ -430,7 +435,10 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                         Log.i(TAG, "AUDIOFOCUS_GAIN: ");
                         // Resume playback
                         if (mLossTransientVolume != -1) {
-                            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mLossTransientVolume, 0);
+                            if (AndroidDevices.isAndroidTv)
+                                setVolume(mLossTransientVolume);
+                            else
+                                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mLossTransientVolume, 0);
                             mLossTransientVolume = -1;
                         }
                         if (mLossTransient) {



More information about the Android mailing list