[Android] Position reported by Android Auto does not update correctly if we seek in the song.

Robert Stone git at videolan.org
Wed Oct 14 08:57:23 CEST 2020


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Tue Oct 13 20:54:30 2020 -0700| [ca257fff1ab5aec11ad9b7dee5b5c8458a6803ad] | committer: Nicolas Pomepuy

Position reported by Android Auto does not update correctly if we seek in the song.

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

 application/vlc-android/src/org/videolan/vlc/PlaybackService.kt | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 80df233e92..6132ea0d96 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -108,7 +108,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
     internal lateinit var mediaSession: MediaSessionCompat
     @Volatile
     private var notificationShowing = false
-
+    private var lastTime = 0L
     private var widget = 0
     /**
      * Last widget position update timestamp
@@ -169,6 +169,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 if (BuildConfig.DEBUG) Log.i(TAG, "MediaPlayer.Event.Playing")
                 executeUpdate()
                 publishState()
+                lastTime = time
                 audioFocusHelper.changeAudioFocus(true)
                 if (!wakeLock.isHeld) wakeLock.acquire()
                 showNotification()
@@ -182,7 +183,11 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 if (wakeLock.isHeld) wakeLock.release()
             }
             MediaPlayer.Event.EncounteredError -> executeUpdate()
-            MediaPlayer.Event.PositionChanged -> if (widget != 0) updateWidgetPosition(event.positionChanged)
+            MediaPlayer.Event.PositionChanged -> {
+                if (time < 1000L && time < lastTime) publishState()
+                lastTime = time
+                if (widget != 0) updateWidgetPosition(event.positionChanged)
+            }
             MediaPlayer.Event.ESAdded -> if (event.esChangedType == IMedia.Track.Type.Video && (playlistManager.videoBackground || !playlistManager.switchToVideo())) {
                 /* CbAction notification content intent: resume video or resume audio activity */
                 updateMetadata()



More information about the Android mailing list