[Android] Duck VLC volume on Android TV

Geoffrey Métais git at videolan.org
Fri Nov 10 11:06:53 CET 2017


vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 10 10:52:24 2017 +0100| [cfb21df596b4ba9420aac522e2640f61b3e2d378] | committer: Geoffrey Métais

Duck VLC volume on Android TV

Because all audio stream are aliased on STREAM_MUSIC on TV

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

 .../src/org/videolan/vlc/PlaybackService.java      | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 5c92893f2..b3d87ff4e 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -416,12 +416,22 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
                         // Lower the volume
                         if (isPlaying()) {
-                            final int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
-                            if (audioDuckLevel == -1)
-                                audioDuckLevel = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)/5;
-                            if (volume > audioDuckLevel) {
-                                mLossTransientVolume = volume;
-                                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
+                            if (AndroidDevices.isAndroidTv) {
+                                final int volume = getVolume();
+                                if (audioDuckLevel == -1)
+                                    audioDuckLevel = 20;
+                                if (volume > audioDuckLevel) {
+                                    mLossTransientVolume = volume;
+                                    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
+                                }
+                            } else {
+                                final int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+                                if (audioDuckLevel == -1)
+                                    audioDuckLevel = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)/5;
+                                if (volume > audioDuckLevel) {
+                                    mLossTransientVolume = volume;
+                                    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
+                                }
                             }
                         }
                         break;
@@ -429,7 +439,11 @@ 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