[Android] Ml: MlServices add nbMedia new 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:12:44 2022 +0100| [17650bc2700ea90260b869acc243a3a472ae65b0] | committer: Nicolas Pomepuy

Ml: MlServices add nbMedia new API

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

 medialibrary/jni/medialibrary.cpp                             | 11 +++++++++++
 .../org/videolan/medialibrary/interfaces/media/MlService.java |  1 +
 .../src/org/videolan/medialibrary/media/MlServiceImpl.java    |  7 +++++++
 .../src/org/videolan/medialibrary/stubs/StubMlService.java    |  5 +++++
 4 files changed, 24 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 9d2b19d78e..61becc5bf8 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2249,6 +2249,16 @@ jint sortingCriteria, jboolean desc, jboolean includeMissing)
     return subsRefs;
 }
 
+jint
+getNbMedia(JNIEnv *env, jobject thiz, jobject ml, jint _type)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, ml);
+    medialibrary::IService::Type type = (medialibrary::IService::Type)_type;
+    medialibrary::ServicePtr servicePtr = aml->service(type);
+    if (servicePtr == nullptr) return -1;
+    return servicePtr->nbMedia();
+}
+
 /*
  * Subscriptions
  */
@@ -2597,6 +2607,7 @@ static JNINativeMethod service_methods[] = {
     {"nativeGetNbSubscriptions", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;I)I", (void*)getNbSubscriptions},
     {"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},
 };
 
 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 d42b36c5c3..16118c418e 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
@@ -38,4 +38,5 @@ public abstract class MlService {
     public abstract int getNbSubscriptions();
     public abstract int getNbUnplayedMedia();
     public abstract Subscription[] getSubscriptions(int sort, boolean desc, boolean includeMissing);
+    public abstract int getNbMedia();
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
index 22c134c1af..fd84d47831 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
@@ -67,6 +67,12 @@ public class MlServiceImpl extends MlService {
         return nativeGetSubscriptions(ml, this.type.value, sort, desc, includeMissing);
     }
 
+    @Override
+    public int getNbMedia() {
+        final Medialibrary ml = Medialibrary.getInstance();
+        return nativeGetNbMedia(ml, this.type.value);
+    }
+
     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);
@@ -77,4 +83,5 @@ public class MlServiceImpl extends MlService {
     private native int nativeGetNbSubscriptions(Medialibrary ml, int type);
     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);
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
index 05fe6d42b4..dceb45fd17 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
@@ -56,4 +56,9 @@ public class StubMlService extends MlService {
     public Subscription[] getSubscriptions(int sort, boolean desc, boolean includeMissing) {
         return new Subscription[0];
     }
+
+    @Override
+    public int getNbMedia() {
+        return 0;
+    }
 }



More information about the Android mailing list