[Android] Enable notification bar seek buttons when paused

Robert Stone git at videolan.org
Tue May 30 09:37:05 UTC 2023


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Thu May 25 22:55:25 2023 -0700| [263a7df61199a4ec5cd83e5bbae1c05036ab1cbe] | committer: Robert Stone

Enable notification bar seek buttons when paused

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

 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt    | 14 ++++++++++----
 .../src/org/videolan/vlc/gui/helpers/NotificationHelper.kt |  4 ++--
 .../src/org/videolan/vlc/media/PlayerController.kt         |  2 ++
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 7b674ac4c7..40edf7d84d 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -295,6 +295,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
         @MainThread
         get() = playlistManager.player.pausable
 
+    val isPaused: Boolean
+        @MainThread
+        get() = playlistManager.player.isPaused()
+
     val isShuffling: Boolean
         @MainThread
         get() = playlistManager.shuffling
@@ -1093,7 +1097,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
                 }
             }
         }
-        pscb.setState(state, time, playlistManager.player.getRate())
+        pscb.setState(state, time, if (isPaused) 0f else playlistManager.player.getRate())
         pscb.setActiveQueueItemId(playlistManager.currentIndex.toLong())
         val repeatType = playlistManager.repeating
         val podcastMode = isPodcastMode
@@ -1615,10 +1619,12 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
     @MainThread
     @JvmOverloads
     fun seek(time: Long, length: Double = this.length.toDouble(), fromUser: Boolean = false, fast: Boolean = false) {
-        if (length > 0.0) this.setTime(time, fast) else setPosition((time.toFloat() / NO_LENGTH_PROGRESS_MAX.toFloat()))
-        if (fromUser) {
-            publishState(time)
+        if (length > 0.0) this.setTime(time, fast) else {
+            setPosition((time.toFloat() / NO_LENGTH_PROGRESS_MAX.toFloat()))
+            if (fromUser) publishState(time)
         }
+        // Required to update timeline when paused
+        if (fromUser && isPaused) showNotification()
     }
 
     @MainThread
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
index 2e2dc94312..8e89ac4f80 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
@@ -100,7 +100,7 @@ object NotificationHelper {
         builder.addAction(NotificationCompat.Action(
                 DrawableCache.getDrawableFromMemCache(ctx, "ic_notif_rewind_${Settings.audioJumpDelay}", R.drawable.ic_notif_rewind),
                 ctx.getString(R.string.playback_rewind),
-                buildMediaButtonPendingIntent(ctx, enabledActions, PlaybackStateCompat.ACTION_REWIND, playing)))
+                buildMediaButtonPendingIntent(ctx, enabledActions, PlaybackStateCompat.ACTION_REWIND)))
         /* Play/Pause or Stop */
         if (pausable) {
             if (playing) builder.addAction(NotificationCompat.Action(R.drawable.ic_widget_pause_w, ctx.getString(R.string.pause),
@@ -112,7 +112,7 @@ object NotificationHelper {
         builder.addAction(NotificationCompat.Action(
                 DrawableCache.getDrawableFromMemCache(ctx, "ic_notif_forward_${Settings.audioJumpDelay}", R.drawable.ic_notif_forward),
                 ctx.getString(R.string.playback_forward),
-                buildMediaButtonPendingIntent(ctx, enabledActions, PlaybackStateCompat.ACTION_FAST_FORWARD, playing)))
+                buildMediaButtonPendingIntent(ctx, enabledActions, PlaybackStateCompat.ACTION_FAST_FORWARD)))
         /* Next */
         if (podcastMode) {
             builder.addAction(NotificationCompat.Action(R.drawable.ic_notif_bookmark_add, ctx.getString(R.string.add_bookmark),
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 54c88b7cdc..b5a35a5033 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -117,6 +117,8 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
 
     fun isPlaying() = playbackState == PlaybackStateCompat.STATE_PLAYING
 
+    fun isPaused() = playbackState == PlaybackStateCompat.STATE_PAUSED
+
     fun isVideoPlaying() = !mediaplayer.isReleased && mediaplayer.vlcVout.areViewsAttached()
 
     fun canSwitchToVideo() = getVideoTracksCount() > 0



More information about the Android mailing list