[Android] Update current playlist media meta once loaded

Geoffrey Métais git at videolan.org
Thu Feb 1 11:52:58 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb  1 09:27:58 2018 +0100| [07525dd4ffa0cfa1604cd213972b02c6cd124f33] | committer: Geoffrey Métais

Update current playlist media meta once loaded

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

 .../src/org/videolan/vlc/media/MediaWrapperList.java      | 15 +++++++++++++++
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 15 ++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
index ec7239d0b..40c05d5b4 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
@@ -22,10 +22,13 @@ package org.videolan.vlc.media;
 
 import android.support.annotation.Nullable;
 
+import org.videolan.medialibrary.Medialibrary;
 import org.videolan.medialibrary.media.MediaWrapper;
+import org.videolan.vlc.VLCApplication;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.ListIterator;
 
 public class MediaWrapperList {
     private static final String TAG = "VLC/MediaWrapperList";
@@ -169,6 +172,18 @@ public class MediaWrapperList {
         return mVideoCount == 0;
     }
 
+    public synchronized void updateWithMLMeta() {
+        final ListIterator<MediaWrapper> iter = mInternalList.listIterator();
+        final Medialibrary ml = VLCApplication.getMLInstance();
+        while (iter.hasNext()) {
+            final MediaWrapper media = iter.next();
+            if (media.getId() == 0L) {
+                final MediaWrapper mw = ml.findMedia(media);
+                if (mw.getId() != 0) iter.set(mw);
+            }
+        }
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index d68c110ae..4bf78b06f 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -15,7 +15,10 @@ import org.videolan.libvlc.Media
 import org.videolan.libvlc.MediaPlayer
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.media.MediaWrapper
-import org.videolan.vlc.*
+import org.videolan.vlc.BuildConfig
+import org.videolan.vlc.PlaybackService
+import org.videolan.vlc.R
+import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.gui.preferences.PreferencesFragment
 import org.videolan.vlc.gui.video.VideoPlayerActivity
@@ -113,11 +116,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             val audio = type == Constants.PLAYLIST_TYPE_AUDIO
             val currentMedia = settings.getString(if (audio) "current_song" else "current_media", "")
             if ("" == currentMedia) return at launch
-            val locations = settings.getString(if (audio) "audio_list" else "media_list", "")!!.split(" ".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()
+            val locations = settings.getString(if (audio) "audio_list" else "media_list", "").split(" ".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()
             if (Util.isArrayEmpty(locations)) return at launch
             val playList = async {
-                locations.map { Uri.decode(it) }
-                        .mapTo(ArrayList<MediaWrapper>(locations.size)) { medialibrary.findMedia(MediaWrapper(Uri.parse(it))) }
+                locations.map { Uri.decode(it) }.mapTo(ArrayList<MediaWrapper>(locations.size)) { MediaWrapper(Uri.parse(it)) }
             }.await()
             // load playlist
             shuffling = settings.getBoolean(if (audio) "audio_shuffling" else "media_shuffling", false)
@@ -138,7 +140,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     private fun onPlaylistLoaded() {
         service.onPlaylistLoaded()
-        launch(UI, CoroutineStart.UNDISPATCHED) { determinePrevAndNextIndices() }
+        launch(UI, CoroutineStart.UNDISPATCHED) {
+            determinePrevAndNextIndices()
+            launch { mediaList.updateWithMLMeta() }
+        }
     }
 
     fun play() = player.play()



More information about the Android mailing list