[Android] Pause playback instead of ducking on Android TV

Geoffrey Métais git at videolan.org
Mon Nov 13 13:55:17 CET 2017


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

Pause playback instead of ducking on Android TV

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

 .../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