[Android] Add tracksCount info to Playlist

Geoffrey Métais git at videolan.org
Thu Jul 13 15:29:57 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 13 15:28:43 2017 +0200| [ad20e36870086fd89e4504d588b415ed6c888bed] | committer: Geoffrey Métais

Add tracksCount info to Playlist

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

 medialibrary/jni/medialibrary.cpp                  |  2 +-
 medialibrary/jni/utils.cpp                         |  2 +-
 .../org/videolan/medialibrary/media/Playlist.java  | 24 +++++++++++++++++-----
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 499142214..e011fb8ce 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -925,7 +925,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
     GET_ID(GetMethodID,
            ml_fields.Playlist.initID,
            ml_fields.Playlist.clazz,
-           "<init>", "(JLjava/lang/String;)V");
+           "<init>", "(JLjava/lang/String;I)V");
 
 
     GET_CLASS(ml_fields.MediaWrapper.clazz,
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 6a9a19c91..8b4b08d53 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -139,7 +139,7 @@ convertPlaylistObject(JNIEnv* env, fields *fields, medialibrary::PlaylistPtr con
 {
     jstring name = env->NewStringUTF(playlistPtr->name().c_str());
     jobject item = env->NewObject(fields->Playlist.clazz, fields->Playlist.initID,
-                          (jlong) playlistPtr->id(), name);
+                          (jlong) playlistPtr->id(), name, (jint)playlistPtr->media().size());
     env->DeleteLocalRef(name);
     return item;
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
index 783f2ef09..73d4c441a 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
@@ -9,18 +9,21 @@ import java.util.List;
 
 public class Playlist extends MediaLibraryItem {
 
-    protected Playlist(long id, String name) {
-        super(id, name);
-    }
+    private int mTracksCount;
 
-    protected Playlist(Parcel in) {
-        super(in);
+    protected Playlist(long id, String name, int trackCount) {
+        super(id, name);
+        mTracksCount = trackCount;
     }
 
     public MediaWrapper[] getTracks(Medialibrary ml) {
         return ml != null && ml.isInitiated() ? nativeGetTracksFromPlaylist(ml, mId) : Medialibrary.EMPTY_COLLECTION;
     }
 
+    public int getTracksCount() {
+        return mTracksCount;
+    }
+
     @Override
     public int getItemType() {
         return TYPE_PLAYLIST;
@@ -70,6 +73,17 @@ public class Playlist extends MediaLibraryItem {
         }
     };
 
+    @Override
+    public void writeToParcel(Parcel parcel, int i) {
+        super.writeToParcel(parcel, i);
+        parcel.writeInt(mTracksCount);
+    }
+
+    private Playlist(Parcel in) {
+        super(in);
+        this.mTracksCount = in.readInt();
+    }
+
     private native MediaWrapper[] nativeGetTracksFromPlaylist(Medialibrary ml, long id);
     private native boolean nativePlaylistAppend(Medialibrary ml, long id, long mediaId);
     private native boolean nativePlaylistAppendGroup(Medialibrary ml, long id, long[] mediaIds);



More information about the Android mailing list