[Android] Fix metadata update for web radios

Nicolas Pomepuy git at videolan.org
Tue Aug 3 10:13:51 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jul 16 14:23:12 2021 +0200| [9455f43ac512fe28b726c75d158fa1e31b8f47a2] | committer: Nicolas Pomepuy

Fix metadata update for web radios

The miniplayer, notification and widget are now updated
when the web radio current played track changes
Fixes #1573

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt       |  1 -
 .../src/org/videolan/vlc/media/PlaylistManager.kt       |  9 +++++++++
 libvlc/src/org/videolan/libvlc/Media.java               | 17 ++++++++++++++---
 libvlc/src/org/videolan/libvlc/interfaces/IMedia.java   |  2 ++
 libvlc/src/org/videolan/libvlc/stubs/StubMedia.java     |  5 +++++
 .../medialibrary/interfaces/media/MediaWrapper.java     |  4 ++--
 6 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 84e0a1148..83e2f71c3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -77,7 +77,6 @@ import org.videolan.vlc.util.share
 import org.videolan.vlc.viewmodels.BookmarkModel
 import org.videolan.vlc.viewmodels.PlaybackProgress
 import org.videolan.vlc.viewmodels.PlaylistModel
-import java.text.DateFormat.SHORT
 import java.text.DateFormat.getTimeInstance
 import java.util.*
 import kotlin.math.absoluteValue
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 ea9d2c0a7..0b387e395 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -910,6 +910,15 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 MediaPlayer.Event.SeekableChanged -> if (event.seekable && settings.getBoolean(if(player.isVideoPlaying()) KEY_PLAYBACK_SPEED_PERSIST_VIDEO else KEY_PLAYBACK_SPEED_PERSIST, false)) {
                     player.setRate(settings.getFloat(if(player.isVideoPlaying()) KEY_PLAYBACK_RATE_VIDEO else KEY_PLAYBACK_RATE, 1.0f), false)
                 }
+                MediaPlayer.Event.ESSelected -> {
+                    getCurrentMedia()?.let { media ->
+                        if (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()
+                        }
+                    }
+                }
             }
             service.onMediaPlayerEvent(event)
         }
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 8eec5dda5..58a40eceb 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -23,6 +23,8 @@ package org.videolan.libvlc;
 import android.content.res.AssetFileDescriptor;
 import android.net.Uri;
 
+import androidx.annotation.Nullable;
+
 import org.videolan.libvlc.interfaces.ILibVLC;
 import org.videolan.libvlc.interfaces.IMedia;
 import org.videolan.libvlc.interfaces.IMediaList;
@@ -32,8 +34,6 @@ import org.videolan.libvlc.util.VLCUtil;
 
 import java.io.FileDescriptor;
 
-import androidx.annotation.Nullable;
-
 @SuppressWarnings("unused, JniMissingFunction")
 public class Media extends VLCObject<IMedia.Event> implements IMedia {
     private final static String TAG = "LibVLC/Media";
@@ -420,10 +420,21 @@ public class Media extends VLCObject<IMedia.Event> implements IMedia {
      * @return meta or null if not found
      */
     public String getMeta(int id) {
+        return getMeta(id, false);
+    }
+
+    /**
+     * Get a Meta.
+     *
+     * @param id see {@link Meta}
+     * @param force force the native call to be done
+     * @return meta or null if not found
+     */
+    public String getMeta(int id, boolean force) {
         if (id < 0 || id >= Meta.MAX)
             return null;
 
-        synchronized (this) {
+        if (!force) synchronized (this) {
             if (mNativeMetas[id] != null)
                 return mNativeMetas[id];
             if (isReleased())
diff --git a/libvlc/src/org/videolan/libvlc/interfaces/IMedia.java b/libvlc/src/org/videolan/libvlc/interfaces/IMedia.java
index ebdce3102..151e38e90 100644
--- a/libvlc/src/org/videolan/libvlc/interfaces/IMedia.java
+++ b/libvlc/src/org/videolan/libvlc/interfaces/IMedia.java
@@ -362,6 +362,8 @@ public interface IMedia extends IVLCObject<IMedia.Event> {
 
     String getMeta(int id);
 
+    String getMeta(int id, boolean force);
+
     void setHWDecoderEnabled(boolean enabled, boolean force);
 
     void setEventListener(EventListener listener);
diff --git a/libvlc/src/org/videolan/libvlc/stubs/StubMedia.java b/libvlc/src/org/videolan/libvlc/stubs/StubMedia.java
index 5dc0954c6..ae8db5b28 100644
--- a/libvlc/src/org/videolan/libvlc/stubs/StubMedia.java
+++ b/libvlc/src/org/videolan/libvlc/stubs/StubMedia.java
@@ -100,6 +100,11 @@ public class StubMedia extends StubVLCObject<IMedia.Event> implements IMedia {
         return null;
     }
 
+    @Override
+    public String getMeta(int id, boolean force) {
+        return getMeta(id);
+    }
+
     private String getTitle() {
         if ("file".equals(mUri.getScheme())) {
             return mUri.getLastPathSegment();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
index 3dc0aad60..581ae10a0 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -372,7 +372,7 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
     }
 
     private static String getMetaId(IMedia media, String defaultMeta, int id, boolean trim) {
-        String meta = media.getMeta(id);
+        String meta = media.getMeta(id, true);
         return meta != null ? trim ? meta.trim() : meta : defaultMeta;
     }
 
@@ -399,7 +399,7 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
     }
 
     public void updateMeta(MediaPlayer mediaPlayer) {
-        if (!TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mDisplayTitle))
+        if ((!TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mDisplayTitle)) || !mDisplayTitle.equals(mTitle))
             mDisplayTitle = mTitle;
         final IMedia media = mediaPlayer.getMedia();
         if (media == null)



More information about the Android mailing list