[Android] Fix the media time update when navigating the play queue

Nicolas Pomepuy git at videolan.org
Tue Oct 5 05:27:05 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Sep 29 10:15:38 2021 +0200| [77fef6cb2b36dec1cf0fc6b8a062b59cc754c29a] | committer: Nicolas Pomepuy

Fix the media time update when navigating the play queue

It needs a medialibrary API change to be fully optimised
See https://code.videolan.org/videolan/medialibrary/-/issues/369
Fixes #2189

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

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt         | 1 +
 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt     | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 50d9ccfd6..05763ed3a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1506,6 +1506,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
     override fun onSelectionSet(position: Int) = overlayDelegate.playlist.scrollToPosition(position)
 
     override fun playItem(position: Int, item: MediaWrapper) {
+        service?.saveMediaMeta()
         service?.playlistManager?.getMedia(position)
         service?.playlistManager?.getMediaList()?.let {
             if (it[position] == item)  service?.playIndex(position)
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 0ab41a50c..020be83e4 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -225,7 +225,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     @MainThread
     fun next(force : Boolean = false) {
-        mediaList.getMedia(currentIndex)?.let { if (it.type == MediaWrapper.TYPE_VIDEO) it.time = player.getCurrentTime() }
+        mediaList.getMedia(currentIndex)?.let { if (it.type == MediaWrapper.TYPE_VIDEO) saveMediaMeta() }
         val size = mediaList.size()
         if (force || repeating != PlaybackStateCompat.REPEAT_MODE_ONE) {
             previous.push(currentIndex)
@@ -283,7 +283,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     @MainThread
     fun previous(force: Boolean) {
-        mediaList.getMedia(currentIndex)?.let { if (it.type == MediaWrapper.TYPE_VIDEO) it.time = player.getCurrentTime() }
+        mediaList.getMedia(currentIndex)?.let { if (it.type == MediaWrapper.TYPE_VIDEO) saveMediaMeta() }
         if (hasPrevious() &&
                 ((force || !player.seekable || (player.getCurrentTime() < PREVIOUS_LIMIT_DELAY) || (lastPrevious != -1L && System.currentTimeMillis() - lastPrevious < PREVIOUS_LIMIT_DELAY)))) {
             val size = mediaList.size()
@@ -487,11 +487,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     media.position = player.lastPosition
                     medialibrary.setLastPosition(media.id, media.position)
                 } else {
-                    media.time = time
                     //todo verify that this info is persisted in DB
                     if (media.length <= 0 && length > 0) media.length = length
 
                     medialibrary.setLastTime(media.id, time)
+                    //todo this is not really optimised. The ML should return the new time value right away to let us save the processed new time.
+                    // See https://code.videolan.org/videolan/medialibrary/-/issues/369
+                    media.time = medialibrary.getMedia(media.id).time
                 }
             }
             media.setStringMeta(MediaWrapper.META_SPEED, rate.toString())



More information about the Android mailing list