[Android] Ml: Subscriptions 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 15:58:28 2022 +0100| [46c5f376161132e8969c033e6c4f449e92fd8644] | committer: Nicolas Pomepuy

Ml: Subscriptions add nbMedia new API

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

 medialibrary/jni/medialibrary.cpp                          | 14 ++++++++++++--
 .../medialibrary/interfaces/media/Subscription.java        |  1 +
 .../org/videolan/medialibrary/media/SubscriptionImpl.java  |  7 +++++++
 .../org/videolan/medialibrary/stubs/StubSubscription.java  |  5 +++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index ce2c81d104..9d2b19d78e 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2303,7 +2303,7 @@ getSubscriptionNbUnplayedMedia(JNIEnv *env, jobject thiz, jobject medialibrary,
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
     medialibrary::SubscriptionPtr subscriptionPtr = aml->subscription(id);
-    if (subscriptionPtr == nullptr) return false;
+    if (subscriptionPtr == nullptr) return -1;
     return subscriptionPtr->nbUnplayedMedia();
 }
 
@@ -2368,6 +2368,15 @@ getSubscriptionMedia(JNIEnv* env, jobject thiz, jobject ml, jlong id, jint sorti
    return subsRefs;   
 }
 
+jint getSubscriptionNbMedia(JNIEnv* env, jobject thiz, jobject ml, jlong id)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, ml);
+    medialibrary::SubscriptionPtr subscriptionPtr = aml->subscription(id);
+    if (subscriptionPtr == nullptr) return -1;
+    return subscriptionPtr->nbMedia();
+}
+
+
  /*
   * JNI stuff
   */
@@ -2600,7 +2609,8 @@ static JNINativeMethod subscription_methods[] = {
     {"nativeGetChildSubscriptions", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JIZZ)[Lorg/videolan/medialibrary/interfaces/media/Subscription;", (void*)getChildSubscriptions},
     {"nativeGetParent", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Lorg/videolan/medialibrary/interfaces/media/Subscription;", (void*)getParent},
     {"nativeSubscriptionRefresh", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Z", (void*)refresh},
-    {"nativeGetSubscriptionMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JIZZ)[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getSubscriptionMedia}
+    {"nativeGetSubscriptionMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JIZZ)[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getSubscriptionMedia},
+    {"nativeGetSubscriptionNbMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)I", (void*)getSubscriptionNbMedia},
 };
 
 /* This function is called when a thread attached to the Java VM is canceled or
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Subscription.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Subscription.java
index 1583fadafb..ce1cbacb5f 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Subscription.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Subscription.java
@@ -34,4 +34,5 @@ public abstract class Subscription {
     public abstract Subscription getParent();
     public abstract MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing);
     public abstract boolean refresh();
+    public abstract int getNbMedia();
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java b/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
index 09c03aeca6..6f0b10f16e 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/SubscriptionImpl.java
@@ -75,6 +75,12 @@ public class SubscriptionImpl extends Subscription {
         return nativeGetSubscriptionMedia(ml, id, sortingCriteria, desc, includeMissing);
     }
 
+    @Override
+    public int getNbMedia() {
+        final Medialibrary ml = Medialibrary.getInstance();
+        return nativeGetSubscriptionNbMedia(ml, id);
+    }
+
     private native int nativeSubscriptionNewMediaNotification(Medialibrary ml, long id);
     private native boolean nativeSetSubscriptionNewMediaNotification(Medialibrary ml, long id, int value);
     private native long nativeGetSubscriptionCachedSize(Medialibrary ml, long id);
@@ -85,4 +91,5 @@ public class SubscriptionImpl extends Subscription {
     private native Subscription nativeGetParent(Medialibrary ml, long id);
     private native boolean nativeSubscriptionRefresh(Medialibrary ml, long id);
     private native MediaWrapper[] nativeGetSubscriptionMedia(Medialibrary ml, long id, int sortingCriteria, boolean desc, boolean includeMissing);
+    private native int nativeGetSubscriptionNbMedia(Medialibrary ml, long id);
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubSubscription.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubSubscription.java
index 5d086409fe..cd222e446e 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubSubscription.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubSubscription.java
@@ -63,4 +63,9 @@ public class StubSubscription extends Subscription {
     public boolean refresh() {
         return false;
     }
+
+    @Override
+    public int getNbMedia() {
+        return 0;
+    }
 }



More information about the Android mailing list