[Android] Fix media not added to history

Nicolas Pomepuy git at videolan.org
Thu Jul 15 11:23:53 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul 13 07:57:22 2021 +0200| [ad4cb6122f63feb4ebf5de85aea83ca546644d9f] | committer: Nicolas Pomepuy

Fix media not added to history

Fixes #2095

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

 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt     | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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 cb299941f..d82668b61 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -903,7 +903,9 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             var id = mw.id
             if (id == 0L) {
                 var internalMedia = medialibrary.findMedia(mw)
-                if (internalMedia == null || internalMedia.id == 0L) {
+                if (internalMedia != null && internalMedia.id != 0L) {
+                    id = internalMedia.id
+                } else {
                     internalMedia = if (mw.type == MediaWrapper.TYPE_STREAM) {
                         medialibrary.addStream(entryUrl ?: mw.uri.toString(), mw.title).also {
                             entryUrl = null
@@ -912,10 +914,14 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         medialibrary.addMedia(mw.uri.toString(), mw.length)
                     }
                     if (internalMedia != null) {
+                        id = internalMedia.id
                         getCurrentMedia()?.let { currentMedia -> if (internalMedia.title != currentMedia.title) internalMedia.rename(currentMedia.title) }
                     }
                 }
             }
+            val length = player.getLength()
+            val canSwitchToVideo = player.canSwitchToVideo()
+            if (id != 0L && mw.type != MediaWrapper.TYPE_VIDEO && !canSwitchToVideo && !mw.isPodcast) if (length == 0L) medialibrary.setLastPosition(mw.id, 1.0f) else  medialibrary.setLastTime(mw.id, length)
         }
     }
 



More information about the Android mailing list