[Android] Pause playback instead of ducking on Android TV

Geoffrey Métais git at videolan.org
Mon Nov 13 14:08:19 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 13 13:54:26 2017 +0100| [63f5d6c011da7949b126e5a5112b04ae27a3238c] | committer: Geoffrey Métais

Pause playback instead of ducking on Android TV

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

 .../src/org/videolan/vlc/PlaybackService.java      | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 04cb1b618..982f530b2 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -407,23 +407,14 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                     case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT");
                         // Pause playback
-                        mLossTransient = true;
-                        wasPlaying = isPlaying();
-                        if (wasPlaying)
-                            pause();
+                        pausePlayback();
                         break;
                     case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                         Log.i(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
                         // Lower the volume
                         if (isPlaying()) {
                             if (AndroidDevices.isAndroidTv) {
-                                final int volume = getVolume();
-                                if (audioDuckLevel == -1)
-                                    audioDuckLevel = 20;
-                                if (volume > audioDuckLevel) {
-                                    mLossTransientVolume = volume;
-                                    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioDuckLevel, 0);
-                                }
+                                pausePlayback();
                             } else {
                                 final int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
                                 if (audioDuckLevel == -1)
@@ -439,11 +430,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                         Log.i(TAG, "AUDIOFOCUS_GAIN: ");
                         // Resume playback
                         if (mLossTransientVolume != -1) {
-                            if (AndroidDevices.isAndroidTv) {
-                                setVolume(mLossTransientVolume);
-                            } else {
-                                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mLossTransientVolume, 0);
-                            }
+                            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mLossTransientVolume, 0);
                             mLossTransientVolume = -1;
                         }
                         if (mLossTransient) {
@@ -454,6 +441,13 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                         break;
                 }
             }
+
+            private void pausePlayback() {
+                mLossTransient = true;
+                wasPlaying = isPlaying();
+                if (wasPlaying)
+                    pause();
+            }
         };
     }
 



More information about the Android mailing list