[Android] Do not require audiofocus when rendering

Geoffrey Métais git at videolan.org
Wed Feb 14 17:19:19 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 14 17:18:36 2018 +0100| [117db707bc9d95b4fd7018a08b6a01c71ff09e0f] | committer: Geoffrey Métais

Do not require audiofocus when rendering

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

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index e9a919cbc..bc04fd5c6 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -381,7 +381,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         if (mAudioManager == null)
             return;
 
-        if (acquire) {
+        if (acquire && !hasRenderer()) {
             if (!mHasAudioFocus) {
                 final int result = mAudioManager.requestAudioFocus(mAudioFocusListener,
                         AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
@@ -390,12 +390,10 @@ public class PlaybackService extends MediaBrowserServiceCompat{
                     mHasAudioFocus = true;
                 }
             }
-        } else {
-            if (mHasAudioFocus) {
-                mAudioManager.abandonAudioFocus(mAudioFocusListener);
-                mAudioManager.setParameters("bgm_state=false");
-                mHasAudioFocus = false;
-            }
+        } else if (mHasAudioFocus) {
+            mAudioManager.abandonAudioFocus(mAudioFocusListener);
+            mAudioManager.setParameters("bgm_state=false");
+            mHasAudioFocus = false;
         }
     }
 
@@ -1768,6 +1766,8 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         if (wasOnRenderer && !hasRenderer() && canSwitchToVideo()) VideoPlayerActivity.startOpened(VLCApplication.getAppContext(),
                 playlistManager.getCurrentMedia().getUri(), playlistManager.getCurrentIndex());
         playlistManager.getPlayer().setRenderer(item);
+        if (!wasOnRenderer && item != null) changeAudioFocus(false);
+        else if (wasOnRenderer && item == null && isPlaying()) changeAudioFocus(true);
     }
 
     @MainThread



More information about the Android mailing list