[Android] Ml: MlService add new getMedia API
Duncan McNamara
git at videolan.org
Fri Nov 18 12:29:46 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Nov 16 16:54:26 2022 +0100| [33519b0feb1d41c053796bb2c36272845b7fe1ae] | committer: Nicolas Pomepuy
Ml: MlService add new getMedia API
> https://code.videolan.org/videolan/vlc-android/commit/33519b0feb1d41c053796bb2c36272845b7fe1ae
---
medialibrary/jni/medialibrary.cpp | 23 ++++++++++++++++++++++
.../medialibrary/interfaces/media/MlService.java | 1 +
.../videolan/medialibrary/media/MlServiceImpl.java | 8 ++++++++
.../videolan/medialibrary/stubs/StubMlService.java | 6 ++++++
4 files changed, 38 insertions(+)
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 61becc5bf8..576cc0f2c4 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2259,6 +2259,28 @@ getNbMedia(JNIEnv *env, jobject thiz, jobject ml, jint _type)
return servicePtr->nbMedia();
}
+jobjectArray
+getServiceMedia(JNIEnv *env, jobject thiz, jobject medialibrary, jint _type,
+jint sortingCriteria, jboolean desc, jboolean includeMissing)
+{
+ AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
+ medialibrary::IService::Type type = (medialibrary::IService::Type)_type;
+ medialibrary::ServicePtr servicePtr = aml->service(type);
+ if (servicePtr == nullptr) {
+ return (jobjectArray) env->NewObjectArray(0, ml_fields.MediaWrapper.clazz, NULL);
+ }
+ medialibrary::QueryParameters params = generateParams(sortingCriteria, desc, includeMissing);
+ std::vector<medialibrary::MediaPtr> mediasArray = servicePtr->media(¶ms)->all();
+ jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mediasArray.size(),
+ ml_fields.MediaWrapper.clazz, NULL);
+ int index = -1;
+ for (medialibrary::MediaPtr const& media : mediasArray) {
+ auto item = mediaToMediaWrapper(env, &ml_fields, media);
+ env->SetObjectArrayElement(mediaRefs, ++index, item.get());
+ }
+ return mediaRefs;
+}
+
/*
* Subscriptions
*/
@@ -2608,6 +2630,7 @@ static JNINativeMethod service_methods[] = {
{"nativeGetNbUnplayedMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;I)I", (void*)getNbUnplayedMedia},
{"nativeGetSubscriptions", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;IIZZ)[Lorg/videolan/medialibrary/interfaces/media/Subscription;", (void*)getSubscriptions},
{"nativeGetNbMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;I)I", (void*)getNbMedia},
+ {"nativeGetServiceMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;IIZZ)[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getServiceMedia},
};
static JNINativeMethod subscription_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
index 16118c418e..b53055e953 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
@@ -39,4 +39,5 @@ public abstract class MlService {
public abstract int getNbUnplayedMedia();
public abstract Subscription[] getSubscriptions(int sort, boolean desc, boolean includeMissing);
public abstract int getNbMedia();
+ public abstract MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing);
}
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
index fd84d47831..c4e37d4c0f 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
@@ -1,6 +1,7 @@
package org.videolan.medialibrary.media;
import org.videolan.medialibrary.interfaces.Medialibrary;
+import org.videolan.medialibrary.interfaces.media.MediaWrapper;
import org.videolan.medialibrary.interfaces.media.MlService;
import org.videolan.medialibrary.interfaces.media.Subscription;
@@ -73,6 +74,12 @@ public class MlServiceImpl extends MlService {
return nativeGetNbMedia(ml, this.type.value);
}
+ @Override
+ public MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing) {
+ final Medialibrary ml = Medialibrary.getInstance();
+ return nativeGetServiceMedia(ml, this.type.value, sortingCriteria, desc, includeMissing);
+ }
+
private native boolean nativeAddSubscription(Medialibrary ml, int type, String mrl);
private native boolean nativeIsAutoDownloadEnabled(Medialibrary ml, int type);
private native boolean nativeSetAutoDownloadEnabled(Medialibrary ml, int type, boolean enabled);
@@ -84,4 +91,5 @@ public class MlServiceImpl extends MlService {
private native int nativeGetNbUnplayedMedia(Medialibrary ml, int type);
private native Subscription[] nativeGetSubscriptions(Medialibrary ml, int type, int sort, boolean desc, boolean includeMissing);
private native int nativeGetNbMedia(Medialibrary ml, int type);
+ private native MediaWrapper[] nativeGetServiceMedia(Medialibrary ml, int type, int sort, boolean desc, boolean includeMissing);
}
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
index dceb45fd17..38657e420f 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
@@ -1,5 +1,6 @@
package org.videolan.medialibrary.stubs;
+import org.videolan.medialibrary.interfaces.media.MediaWrapper;
import org.videolan.medialibrary.interfaces.media.MlService;
import org.videolan.medialibrary.interfaces.media.Subscription;
@@ -57,6 +58,11 @@ public class StubMlService extends MlService {
return new Subscription[0];
}
+ @Override
+ public MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing) {
+ return new MediaWrapper[0];
+ }
+
@Override
public int getNbMedia() {
return 0;
More information about the Android
mailing list