[Android] MediaWrapper: add cond to updateMeta for title

Duncan McNamara git at videolan.org
Tue Mar 14 11:59:20 UTC 2023


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

MediaWrapper: add cond to updateMeta 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. Network share will have null filenames though,
meaning that libvlc will never be chosen, hence the check for directory
type in the condition

Fixes #2722

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

 .../interfaces/media/MediaWrapper.java             | 25 ++++++++++++++++++++--
 1 file changed, 23 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 73c4fd3c47..d48355fdac 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -381,8 +381,29 @@ 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.
+     * This won't work for network shares as they will return null titles, so
+     * they are exempted as directories
+     * @param media media to update
+     * @return title string
+     */
+    private String getMetaTitle(IMedia media) {
+        String libvlcTitle = getMetaId(media, mTitle, Media.Meta.Title, true);
+        String fileName = getFileName();
+        if (media.getType() == Media.Type.Directory ||
+                (!TextUtils.isEmpty(libvlcTitle) && !libvlcTitle.equals(fileName)))
+            return libvlcTitle;
+        return getTitle();
+    }
+
+    private void  updateMeta(IMedia media) {
+        mTitle = getMetaTitle(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