[Android] Reuse playback notification if available
Geoffrey Métais
git at videolan.org
Thu Jan 17 15:58:14 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan 17 15:57:49 2019 +0100| [8decaa38a21224a61183c472919c01b3193ede4f] | committer: Geoffrey Métais
Reuse playback notification if available
> https://code.videolan.org/videolan/vlc-android/commit/8decaa38a21224a61183c472919c01b3193ede4f
---
vlc-android/src/org/videolan/vlc/PlaybackService.kt | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 5bc041817..da0db0efc 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -21,6 +21,7 @@ package org.videolan.vlc
import android.annotation.TargetApi
import android.app.KeyguardManager
+import android.app.Notification
import android.app.PendingIntent
import android.app.SearchManager
import android.app.Service
@@ -565,13 +566,14 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
private fun forceForeground() {
val ctx = this at PlaybackService
- val notification = NotificationHelper.createPlaybackNotification(ctx,false,
+ val stopped = playlistManager.player.playbackState == PlaybackStateCompat.STATE_STOPPED
+ val notification = if (this::notification.isInitialized && !stopped) notification
+ else NotificationHelper.createPlaybackNotification(ctx,false,
ctx.resources.getString(R.string.loading), "", "",null,
false, mediaSession.sessionToken, sessionPendingIntent)
startForeground(3, notification)
isForeground = true
- if (isVideoPlaying || AndroidDevices.showTvUi(this)
- || playlistManager.player.playbackState == PlaybackStateCompat.STATE_STOPPED) hideNotification(true)
+ if (isVideoPlaying || AndroidDevices.showTvUi(this) || stopped) hideNotification(true)
}
private fun sendStartSessionIdIntent() {
@@ -677,7 +679,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
if (cover == null || cover.isRecycled)
cover = BitmapFactory.decodeResource(ctx.resources, R.drawable.ic_no_media)
- val notification = NotificationHelper.createPlaybackNotification(ctx,
+ notification = NotificationHelper.createPlaybackNotification(ctx,
mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO), title, artist, album,
cover, playing, sessionToken, sessionPendingIntent)
if (isPlayingPopup) return at launch
@@ -703,6 +705,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
}
}
}
+ private lateinit var notification : Notification
private fun currentMediaHasFlag(flag: Int): Boolean {
val mw = playlistManager.getCurrentMedia()
More information about the Android
mailing list