[Android] Real track count for Albums and Playlist

Geoffrey Métais git at videolan.org
Thu Sep 13 15:06:34 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 13 15:04:14 2018 +0200| [db08ffd9fe06ce544b714e653d26f40e0cb3c527] | committer: Geoffrey Métais

Real track count for Albums and Playlist

Regular count could be out of date

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

 medialibrary/jni/medialibrary.cpp                              | 6 ++++++
 medialibrary/src/org/videolan/medialibrary/media/Album.java    | 6 ++++++
 medialibrary/src/org/videolan/medialibrary/media/Playlist.java | 5 +++++
 3 files changed, 17 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index cb34dc49f..c4e58f43f 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -957,6 +957,11 @@ getTracksFromAlbum(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, ji
     return filteredArray(env, mediaRefs, ml_fields.MediaWrapper.clazz, drops);
 }
 
+jint
+getTracksFromAlbumCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id) {
+    return (jint) MediaLibrary_getInstance(env, medialibrary)->tracksFromAlbum(id, nullptr)->count();
+}
+
 jobjectArray
 getPagedTracksFromAlbum(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint sortingCriteria, jboolean desc, jint nbItems,  jint offset)
 {
@@ -1643,6 +1648,7 @@ static JNINativeMethod album_methods[] = {
     {"nativeGetPagedTracks", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getPagedTracksFromAlbum },
     {"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)searchFromAlbum },
     {"nativeGetSearchCount", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;)I", (void*)getSearchFromAlbumCount },
+    {"nativeGetTracksCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)getTracksFromAlbumCount },
 };
 
 static JNINativeMethod artist_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Album.java b/medialibrary/src/org/videolan/medialibrary/media/Album.java
index 630dc5245..82febe9c6 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Album.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Album.java
@@ -63,6 +63,11 @@ public class Album extends MediaLibraryItem {
         return mTracksCount;
     }
 
+    public int getRealTracksCount() {
+        Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeGetTracksCount(ml, mId) : 0;
+    }
+
     public int getDuration() {
         return duration;
     }
@@ -99,6 +104,7 @@ public class Album extends MediaLibraryItem {
     private native MediaWrapper[] nativeGetTracks(Medialibrary ml, long mId, int sort, boolean desc);
     private native MediaWrapper[] nativeGetPagedTracks(Medialibrary ml, long mId, int sort, boolean desc, int nbItems, int offset);
     private native MediaWrapper[] nativeSearch(Medialibrary ml, long mId, String query, int sort, boolean desc, int nbItems, int offset);
+    private native int nativeGetTracksCount(Medialibrary ml, long id);
     private native int nativeGetSearchCount(Medialibrary ml, long mId, String query);
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
index a214d7cc3..59bc58da3 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
@@ -30,6 +30,11 @@ public class Playlist extends MediaLibraryItem {
         return mTracksCount;
     }
 
+    public int getRealTracksCount() {
+        Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeGetTracksCount(ml, mId) : 0;
+    }
+
     @Override
     public int getItemType() {
         return TYPE_PLAYLIST;



More information about the Android mailing list