[Android] Implement new ML playlist APIs

Nicolas Pomepuy git at videolan.org
Fri Jan 7 11:53:57 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 18 08:23:50 2021 +0100| [024d7ff5c0967692f416e4adb70afb53711df6d9] | committer: Nicolas Pomepuy

Implement new ML playlist APIs

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt  |  1 -
 .../src/org/videolan/vlc/util/Kextensions.kt       |  9 +++++++-
 medialibrary/jni/medialibrary.cpp                  |  2 +-
 medialibrary/jni/utils.cpp                         |  2 +-
 .../videolan/medialibrary/MLServiceLocator.java    |  6 ++---
 .../medialibrary/interfaces/media/Playlist.java    | 26 +++++++++++++++++++++-
 .../videolan/medialibrary/media/PlaylistImpl.java  |  4 ++--
 .../medialibrary/stubs/StubMedialibrary.java       |  2 +-
 .../videolan/medialibrary/stubs/StubPlaylist.java  |  4 ++--
 9 files changed, 43 insertions(+), 13 deletions(-)

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 e3fac3df1..3b0c499fe 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -31,7 +31,6 @@ import org.videolan.vlc.R
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.util.*
 import org.videolan.vlc.util.FileUtils
-import java.lang.Exception
 import java.security.SecureRandom
 import java.util.*
 import kotlin.math.max
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 118f894bf..ffe9ec634 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -34,10 +34,12 @@ import kotlinx.coroutines.flow.collect
 import org.videolan.libvlc.Media
 import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.libvlc.util.AndroidUtil
+import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.interfaces.media.MediaWrapper.TYPE_ALL
 import org.videolan.medialibrary.interfaces.media.MediaWrapper.TYPE_VIDEO
+import org.videolan.medialibrary.interfaces.media.Playlist
 import org.videolan.medialibrary.interfaces.media.VideoGroup
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.AndroidDevices
@@ -46,6 +48,7 @@ import org.videolan.tools.AppScope
 import org.videolan.tools.isStarted
 import org.videolan.vlc.R
 import java.io.File
+import java.lang.StringBuilder
 import java.net.URI
 import java.net.URISyntaxException
 import java.security.SecureRandom
@@ -171,7 +174,11 @@ fun asyncTextItem(view: TextView, item: MediaLibraryItem?) {
         view.visibility = View.GONE
         return
     }
-    val text = if (item.itemType == MediaLibraryItem.TYPE_PLAYLIST) view.context.getString(R.string.track_number, item.tracksCount) else item.description
+    val text = if (item is Playlist){
+        val sb = StringBuilder(view.context.getString(R.string.track_number, item.tracksCount))
+        if (item.duration != 0L) sb.append(" ยท ${Tools.millisToString(item.duration)}")
+        sb.toString()
+    } else item.description
     if (text.isNullOrEmpty()) {
         view.visibility = View.GONE
         return
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 04ecc34a8..3a4ede9bb 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2287,7 +2287,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
     GET_ID(GetMethodID,
            ml_fields.Playlist.initID,
            ml_fields.Playlist.clazz,
-           "<init>", "(JLjava/lang/String;I)V");
+           "<init>", "(JLjava/lang/String;IJIII)V");
 
 
     GET_CLASS(ml_fields.MediaWrapper.clazz,
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 4743712ec..53d992881 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -127,7 +127,7 @@ convertPlaylistObject(JNIEnv* env, fields *fields, medialibrary::PlaylistPtr con
            static_cast<bool>( includeMissing )
         };
     return utils::jni::object{ env, env->NewObject(fields->Playlist.clazz, fields->Playlist.initID,
-                          (jlong) playlistPtr->id(), name.get(), (jint)playlistPtr->media(&params)->count())
+                          (jlong) playlistPtr->id(), name.get(), (jint)playlistPtr->media(&params)->count(), (jlong)playlistPtr->duration(), (jint)playlistPtr->nbVideo(), (jint)playlistPtr->nbAudio(), (jint)playlistPtr->nbUnknown())
     };
 }
 
diff --git a/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java b/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
index 2b4503a27..fa8fd3bf5 100644
--- a/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
+++ b/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
@@ -220,11 +220,11 @@ public class MLServiceLocator {
     }
 
     //Playlist
-    public static Playlist getAbstractPlaylist(long id, String name, int trackCount) {
+    public static Playlist getAbstractPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
         if (sMode == LocatorMode.VLC_ANDROID) {
-            return new PlaylistImpl(id, name, trackCount);
+            return new PlaylistImpl(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
         } else {
-            return new StubPlaylist(id, name, trackCount);
+            return new StubPlaylist(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
         }
     }
 
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
index 7be22ea41..1a065e142 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
@@ -11,10 +11,18 @@ import java.util.List;
 public abstract class Playlist extends MediaLibraryItem {
 
     protected int mTracksCount;
+    protected long mDuration;
+    protected long mNbVideo;
+    protected long mNbAudio;
+    protected long mNbUnknown;
 
-    protected Playlist(long id, String name, int trackCount) {
+    protected Playlist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
         super(id, name);
         mTracksCount = trackCount;
+        mDuration = duration;
+        mNbVideo = nbVideo;
+        mNbAudio = nbAudio;
+        mNbUnknown = nbUnknown;
     }
 
     abstract public MediaWrapper[] getTracks(boolean includeMissing);
@@ -35,6 +43,22 @@ public abstract class Playlist extends MediaLibraryItem {
         return mTracksCount;
     }
 
+    public long getDuration() {
+        return mDuration;
+    }
+
+    public long getNbVideo() {
+        return mNbVideo;
+    }
+
+    public long getNbAudio() {
+        return mNbAudio;
+    }
+
+    public long getNbUnknown() {
+        return mNbUnknown;
+    }
+
     @Override
     public int getItemType() {
         return TYPE_PLAYLIST;
diff --git a/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java b/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
index f6b930160..98ae29c86 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
@@ -11,8 +11,8 @@ import java.util.List;
 @SuppressWarnings("JniMissingFunction")
 public class PlaylistImpl extends Playlist {
 
-    public PlaylistImpl(long id, String name, int trackCount) {
-        super(id, name, trackCount);
+    public PlaylistImpl(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
+        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
     }
 
     public PlaylistImpl(Parcel in) {
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index 070ffa8ce..e086d3604 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -341,7 +341,7 @@ public class StubMedialibrary extends Medialibrary {
     }
 
     public Playlist createPlaylist(String name, boolean includeMissing) {
-        Playlist playlist = MLServiceLocator.getAbstractPlaylist(dt.getUUID(), name, 0);
+        Playlist playlist = MLServiceLocator.getAbstractPlaylist(dt.getUUID(), name, 0, 0L, 0, 0, 0);
         dt.mPlaylists.add(playlist);
         onPlaylistsAdded();
         return playlist;
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
index f3a823aa7..60181ff8f 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
@@ -15,8 +15,8 @@ public class StubPlaylist extends Playlist {
     private ArrayList<Long> mTracksId = new ArrayList<>();
     private StubDataSource dt = StubDataSource.getInstance();
 
-    public StubPlaylist(long id, String name, int trackCount) {
-        super(id, name, trackCount);
+    public StubPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
+        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
     }
 
     public StubPlaylist(Parcel in) {



More information about the Android mailing list