[Android] Keep playbackservice foreground during phone calls

Geoffrey Métais git at videolan.org
Tue Feb 13 18:49:44 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 13 17:00:00 2018 +0100| [ce42f4637149aa73c7c1e57bf34719fdc65fe8a7] | committer: Geoffrey Métais

Keep playbackservice foreground during phone calls

As audio focus loss is only transient, there is no reason to remove
service from foreground

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

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 350e23cdb..e9a919cbc 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -300,10 +300,10 @@ public class PlaybackService extends MediaBrowserServiceCompat{
 
     private final OnAudioFocusChangeListener mAudioFocusListener = createOnAudioFocusChangeListener();
 
+    private volatile boolean mLossTransient = false;
     private OnAudioFocusChangeListener createOnAudioFocusChangeListener() {
         return new OnAudioFocusChangeListener() {
             int audioDuckLevel = -1;
-            private boolean mLossTransient = false;
             private int mLossTransientVolume = -1;
             private boolean wasPlaying = false;
 
@@ -369,8 +369,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
                 if (mLossTransient) return;
                 mLossTransient = true;
                 wasPlaying = isPlaying();
-                if (wasPlaying)
-                    pause();
+                if (wasPlaying) pause();
             }
         };
     }
@@ -661,7 +660,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
                                 mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO), title, artist, album,
                                 cover, playing, sessionToken, getSessionPendingIntent());
                         if (isPlayingPopup()) return;
-                        if (!AndroidUtil.isLolliPopOrLater || playing) {
+                        if (!AndroidUtil.isLolliPopOrLater || playing || mLossTransient) {
                             if (!mIsForeground) {
                                 PlaybackService.this.startForeground(3, notification);
                                 mIsForeground = true;



More information about the Android mailing list