[Android] Get medialibrary meta on 'load last playlist'
Geoffrey Métais
git at videolan.org
Mon Oct 29 17:26:19 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct 29 15:46:03 2018 +0100| [0e8d280c37a725310c6af9422f6e2bc3666a67d0] | committer: Geoffrey Métais
Get medialibrary meta on 'load last playlist'
> https://code.videolan.org/videolan/vlc-android/commit/0e8d280c37a725310c6af9422f6e2bc3666a67d0
---
.../src/org/videolan/vlc/media/MediaWrapperList.java | 20 +++++++++++++++++++-
.../src/org/videolan/vlc/media/PlaylistManager.kt | 6 +++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
index 1dbd065b0..2cee1811c 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
@@ -20,10 +20,13 @@
*****************************************************************************/
package org.videolan.vlc.media;
+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;
import androidx.annotation.Nullable;
@@ -143,7 +146,7 @@ public class MediaWrapperList {
}
}
- public int size() {
+ public synchronized int size() {
return mInternalList.size();
}
@@ -169,6 +172,21 @@ public class MediaWrapperList {
return mVideoCount == 0;
}
+ public 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) {
+ if (mw.getType() == MediaWrapper.TYPE_ALL) mw.setType(media.getType());
+ synchronized (this) { 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 b54c394df..1f1ffdf7a 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -104,7 +104,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
@MainThread
- fun load(list: List<MediaWrapper>, position: Int) {
+ fun load(list: List<MediaWrapper>, position: Int, mlUpdate: Boolean = false) {
mediaList.removeEventListener(this)
mediaList.clear()
previous.clear()
@@ -124,6 +124,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
clearABRepeat()
playIndex(currentIndex)
onPlaylistLoaded()
+ if (mlUpdate) launch(Dispatchers.IO) { mediaList.updateWithMLMeta() }
}
}
@@ -159,7 +160,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
val rate = settings.getFloat(PreferencesActivity.VIDEO_SPEED, player.getRate())
if (rate != 1.0f) player.setRate(rate, false)
}
- load(playList, position)
+ load(playList, position, true)
loadingLastPlaylist = false
}
return true
@@ -168,7 +169,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
private suspend fun onPlaylistLoaded() {
service.onPlaylistLoaded()
determinePrevAndNextIndices()
-// launch(Dispatchers.IO) { mediaList.updateWithMLMeta() }
}
fun play() {
More information about the Android
mailing list