[Android] Do not show notification when playback fails

Geoffrey Métais git at videolan.org
Wed Dec 12 18:09:15 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Dec 12 18:00:53 2018 +0100| [43e51385b283fd9e32df51afb7b830817be3654f] | committer: Geoffrey Métais

Do not show notification when playback fails

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

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index e44103e41..20c67e9c4 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -90,6 +90,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
 
     // Playback management
     internal lateinit var mediaSession: MediaSessionCompat
+    @Volatile private var notificationShowing = false
 
     private var widget = 0
     /**
@@ -633,7 +634,10 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         }
     }
 
-    fun showNotification() = cbActor.offer(ShowNotification)
+    fun showNotification() : Boolean {
+        notificationShowing = true
+        return cbActor.offer(ShowNotification)
+    }
 
     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     private fun showNotificationInternal() {
@@ -650,7 +654,8 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
             val ctx = this
             val metaData = mediaSession.controller.metadata
             launch(Dispatchers.Default) {
-                if (isPlayingPopup) return at launch
+                delay(100)
+                if (isPlayingPopup || !notificationShowing) return at launch
                 try {
                     val title = if (metaData == null) mw.title else metaData.getString(MediaMetadataCompat.METADATA_KEY_TITLE)
                     val artist = if (metaData == null) mw.artist else metaData.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST)
@@ -694,7 +699,10 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         return mw != null && mw.hasFlag(flag)
     }
 
-    private fun hideNotification(remove: Boolean) = cbActor.offer(HideNotification(remove))
+    private fun hideNotification(remove: Boolean) : Boolean {
+        notificationShowing = false
+        return cbActor.offer(HideNotification(remove))
+    }
 
     private fun hideNotificationInternal(remove: Boolean) {
         if (!isPlayingPopup && isForeground) {



More information about the Android mailing list