[Android] MediaWrapper: add cond to udpateMeta for title

Duncan McNamara git at videolan.org
Tue Jan 10 12:50:52 UTC 2023


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Nov 23 17:50:59 2022 +0100| [82936d2205cf5aaeb73f0157fccefe71b787df4f] | committer: Nicolas Pomepuy

MediaWrapper: add cond to udpateMeta for title

If libvlc doesn't have any meta for title it will provide the filename.
This can be problematic with m3u8 #EXTINF that provides a title.
This adds a check when updating the title meta. If the libvlc title
provided is equal to the filename then it will proritize the
medialibrary title.

Fixes #2722

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

 .../interfaces/media/MediaWrapper.java             | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
index 6b54d477f0..009cb9a4ea 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -381,8 +381,26 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
         return meta != null ? trim ? meta.trim() : meta : defaultMeta;
     }
 
-    private void updateMeta(IMedia media) {
-        mTitle = getMetaId(media, mTitle, Media.Meta.Title, true);
+    /**
+     * This returns the updated title meta for the media. Though it checks that the title media in
+     * libvlc isn't just the filename as this would mean that libvlc doesn't have any title meta.
+     * This is to ensure that medialibrary titles don't get overriden by default filename.
+     * An example of this would be for a stream in a m3u8 file with and #EXTINF: title parameter.
+     * libvlc won't have access to this meta, and if the stream doesn't send updated metas, then it
+     * will be replaced with the filename even though the medialibrary has a correct title.
+     * @param media media to update
+     * @return title string
+     */
+    private String updateTitleMeta(IMedia media) {
+        String libvlcTitle = getMetaId(media, mTitle, Media.Meta.Title, true);
+        String fileName = getFileName();
+        if (!TextUtils.isEmpty(libvlcTitle) && !TextUtils.isEmpty(fileName) && !libvlcTitle.equals(fileName))
+            return libvlcTitle;
+        return getTitle();
+    }
+
+    private void  updateMeta(IMedia media) {
+        mTitle = updateTitleMeta(media);
         mArtist = getMetaId(media, mArtist, Media.Meta.Artist, true);
         mAlbum = getMetaId(media, mAlbum, Media.Meta.Album, true);
         mGenre = getMetaId(media, mGenre, Media.Meta.Genre, true);



More information about the Android mailing list