[Android] Add last videos method

Geoffrey Métais git at videolan.org
Thu Jun 8 16:05:09 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun  8 16:03:37 2017 +0200| [a139d1b68e6345fa06728b9f542073e62f589760] | committer: Geoffrey Métais

Add last videos method

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

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

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 2791e4b26..9cf788a4c 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -236,11 +236,11 @@ bool clearHistory(JNIEnv* env, jobject thiz)
     return MediaLibrary_getInstance(env, thiz)->clearHistory();
 }
 
-jobjectArray
-getVideos(JNIEnv* env, jobject thiz)
+static jobjectArray
+getInternalVideos(JNIEnv* env, jobject thiz, medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
-    std::vector<medialibrary::MediaPtr> videoFiles = aml->videoFiles();
+    std::vector<medialibrary::MediaPtr> videoFiles = aml->videoFiles(sort, desc);
     jobjectArray videoRefs = (jobjectArray) env->NewObjectArray(videoFiles.size(), ml_fields.MediaWrapper.clazz, NULL);
     int index = -1, drops = 0;
     for(medialibrary::MediaPtr const& media : videoFiles) {
@@ -253,6 +253,18 @@ getVideos(JNIEnv* env, jobject thiz)
     return filteredArray(env, &ml_fields, videoRefs, drops);
 }
 
+jobjectArray
+getVideos(JNIEnv* env, jobject thiz)
+{
+    return getInternalVideos(env, thiz);
+}
+
+jobjectArray
+getRecentVideos(JNIEnv* env, jobject thiz)
+{
+    return getInternalVideos(env, thiz, medialibrary::SortingCriteria::InsertionDate, true);
+}
+
 static jobjectArray
 getInternalAudio(JNIEnv* env, jobject thiz, medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false)
 {
@@ -751,6 +763,7 @@ static JNINativeMethod methods[] = {
     {"nativeAddToHistory", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)addToHistory },
     {"nativeClearHistory", "()Z", (void*)clearHistory },
     {"nativeGetVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getVideos },
+    {"nativeGetRecentVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getRecentVideos },
     {"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},
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 585140a1d..966ed70c7 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -134,6 +134,10 @@ public class Medialibrary {
         return mIsInitiated ? nativeGetVideos() : new MediaWrapper[0];
     }
 
+    public MediaWrapper[] getRecentVideos() {
+        return mIsInitiated ? nativeGetRecentVideos() : new MediaWrapper[0];
+    }
+
     public MediaWrapper[] getAudio() {
         return mIsInitiated ? nativeGetAudio() : new MediaWrapper[0];
     }
@@ -569,6 +573,7 @@ public class Medialibrary {
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
     private native MediaWrapper nativeAddMedia(String mrl);
     private native MediaWrapper[] nativeGetVideos();
+    private native MediaWrapper[] nativeGetRecentVideos();
     private native MediaWrapper[] nativeGetAudio();
     private native MediaWrapper[] nativeGetRecentAudio();
     private native int nativeGetVideoCount();



More information about the Android mailing list