[Android] Add getRecentAudio method for last added songs

Geoffrey Métais git at videolan.org
Wed Mar 22 17:39:08 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 22 17:37:41 2017 +0100| [5fc5b93c3ff8fc511d7bbe0d2a01ae337a121de7] | committer: Geoffrey Métais

Add getRecentAudio method for last added songs

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

 medialibrary/jni/medialibrary.cpp                            | 11 +++++++++--
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java |  5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 732c068..1e43098 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -253,10 +253,10 @@ getVideos(JNIEnv* env, jobject thiz)
 }
 
 jobjectArray
-getAudio(JNIEnv* env, jobject thiz)
+getAudio(JNIEnv* env, jobject thiz, medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
-    std::vector<medialibrary::MediaPtr> audioFiles = aml->audioFiles();
+    std::vector<medialibrary::MediaPtr> audioFiles = aml->audioFiles(sort, desc);
     jobjectArray audioRefs = (jobjectArray) env->NewObjectArray(audioFiles.size(), ml_fields.MediaWrapper.clazz, NULL);
     int index = -1;
     for(medialibrary::MediaPtr const& media : audioFiles) {
@@ -267,6 +267,12 @@ getAudio(JNIEnv* env, jobject thiz)
     return audioRefs;
 }
 
+jobjectArray
+getRecentAudio(JNIEnv* env, jobject thiz)
+{
+    return getAudio(env, thiz, medialibrary::SortingCriteria::InsertionDate, true);
+}
+
 jobject
 search(JNIEnv* env, jobject thiz, jstring query)
 {
@@ -731,6 +737,7 @@ static JNINativeMethod methods[] = {
     {"nativeClearHistory", "()Z", (void*)clearHistory },
     {"nativeGetVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getVideos },
     {"nativeGetAudio", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getAudio },
+    {"nativeGetRecentAudio", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getRecentAudio },
     {"nativeSearch", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/SearchAggregate;", (void*)search},
     {"nativeSearchMedia", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaSearchAggregate;", (void*)searchMedia},
     {"nativeSearchAlbum", "(Ljava/lang/String;)[Lorg/videolan/medialibrary/media/Album;", (void*)searchAlbum },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 3f6b028..3463db2 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -126,6 +126,10 @@ public class Medialibrary {
         return mIsInitiated ? nativeGetAudio() : new MediaWrapper[0];
     }
 
+    public MediaWrapper[] getRecentAudio() {
+        return mIsInitiated ? nativeGetRecentAudio() : new MediaWrapper[0];
+    }
+
     public int getVideoCount() {
         return mIsInitiated ? nativeGetVideoCount() : 0;
     }
@@ -547,6 +551,7 @@ public class Medialibrary {
     private native MediaWrapper nativeAddMedia(String mrl);
     private native MediaWrapper[] nativeGetVideos();
     private native MediaWrapper[] nativeGetAudio();
+    private native MediaWrapper[] nativeGetRecentAudio();
     private native int nativeGetVideoCount();
     private native int nativeGetAudioCount();
     private native  boolean nativeIsWorking();



More information about the Android mailing list