[Android] Fix external media titles set to filename

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Oct  4 15:38:47 2021 +0200| [fd8d827cbe1722b6c9f744bc20478ef4a0cd9fce] | committer: Nicolas Pomepuy

Fix external media titles set to filename

Fixes #1434
Also fixes the streams not added to history

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt  | 25 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

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 020be83e4..91a783368 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -883,6 +883,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         newMedia = false
                         if (player.hasRenderer || !player.isVideoPlaying()) showAudioPlayer.value = true
                         savePlaycount(mw)
+                        if ((mw.title != player.mediaplayer.media?.getMeta(IMedia.Meta.Title, true) || mw.artist != player.mediaplayer.media?.getMeta(IMedia.Meta.Artist, true))) {
+                            // used for initial metadata update. We avoid the metadata load when the initial MediaPlayer.Event.ESSelected is sent to avoid race conditions
+                            refreshTrackMeta(mw)
+                        }
                     }
                 }
                 MediaPlayer.Event.EndReached -> {
@@ -921,10 +925,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 }
                 MediaPlayer.Event.ESSelected -> {
                     getCurrentMedia()?.let { media ->
-                        if (media.id < 1L && (media.title != player.mediaplayer.media?.getMeta(IMedia.Meta.Title, true) || media.artist != player.mediaplayer.media?.getMeta(IMedia.Meta.Artist, true))) {
-                            media.updateMeta(player.mediaplayer)
-                            service.onMediaListChanged()
-                            service.showNotification()
+                        if (player.isPlaying()) {
+                            if ((media.title != player.mediaplayer.media?.getMeta(IMedia.Meta.Title, true) || media.artist != player.mediaplayer.media?.getMeta(IMedia.Meta.Artist, true))) {
+                                refreshTrackMeta(media)
+                            }
                         }
                     }
                 }
@@ -933,6 +937,17 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         }
     }
 
+    /**
+     * Refresh the track meta as the title and then updates the player
+     * Useful for web radios changing the metadata during playback
+     * @param mw: The [MediaWrapper] to be updated
+     */
+    private fun refreshTrackMeta(mw: MediaWrapper) {
+        mw.updateMeta(player.mediaplayer)
+        service.onMediaListChanged()
+        service.showNotification()
+    }
+
     private suspend fun savePlaycount(mw: MediaWrapper) {
         if (settings.getBoolean(PLAYBACK_HISTORY, true)) withContext(Dispatchers.IO) {
             var id = mw.id
@@ -956,7 +971,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             }
             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)
+            if (id != 0L && mw.type != MediaWrapper.TYPE_VIDEO && !canSwitchToVideo && !mw.isPodcast) if (length == 0L) medialibrary.setLastPosition(id, 1.0f) else  medialibrary.setLastTime(id, length)
         }
     }
 



More information about the Android mailing list