[Android] Medialibrary: add jni for media->markAsPlayed()

Duncan McNamara git at videolan.org
Tue May 17 13:30:51 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed May 11 13:49:44 2022 +0200| [793dc7d447b098b248ece710f9ba8d6b031fc9ce] | committer: Duncan McNamara

Medialibrary: add jni for media->markAsPlayed()

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

 medialibrary/jni/medialibrary.cpp                              |  9 +++++++++
 .../videolan/medialibrary/interfaces/media/MediaWrapper.java   |  1 +
 .../src/org/videolan/medialibrary/media/MediaWrapperImpl.java  | 10 ++++++++++
 .../src/org/videolan/medialibrary/stubs/StubMediaWrapper.java  |  3 +++
 4 files changed, 23 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index dd4daf027..93bb66c66 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1440,6 +1440,14 @@ removeAllBookmarks(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
     return media->removeAllBookmarks();
 }
 
+jboolean
+markAsPlayed(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
+    medialibrary::MediaPtr media = aml->media(id);
+    if (media == nullptr) return 0L;
+    return media->markAsPlayed();
+}
+
 jboolean
 setBookmarkName(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jstring name) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
@@ -2142,6 +2150,7 @@ static JNINativeMethod media_methods[] = {
     {"nativeAddBookmark", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JJ)Lorg/videolan/medialibrary/interfaces/media/Bookmark;", (void*)addBookmark },
     {"nativeRemoveBookmark", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JJ)Z", (void*)removeBookmark },
     {"nativeRemoveAllBookmarks", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Z", (void*)removeAllBookmarks },
+    {"nativeMarkAsPlayed", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Z", (void*)markAsPlayed },
 };
 
 static JNINativeMethod bookmark_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
index 2e02001da..63cd6b77e 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -142,6 +142,7 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
     public abstract Bookmark addBookmark(long time);
     public abstract boolean removeBookmark(long time);
     public abstract boolean removeAllBookmarks();
+    public abstract boolean markAsPlayed();
 
     /**
      * Create a new MediaWrapper
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
index 87b3e6d18..c8dcc89bd 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
@@ -287,6 +287,15 @@ public class MediaWrapperImpl extends MediaWrapper {
         if (ml.isInitiated()) nativeRequestThumbnail(ml, mId, Medialibrary.ThumbnailSizeType.Banner.ordinal(), width, 0, position);
     }
 
+    public boolean markAsPlayed() {
+        if (mId == 0L) return false;
+        final Medialibrary ml = Medialibrary.getInstance();
+        boolean ret = false;
+        if (ml.isInitiated())
+            ret = nativeMarkAsPlayed(ml, mId);
+        return ret;
+    }
+
     private native long nativeGetMediaLongMetadata(Medialibrary ml, long id, int metaDataType);
     private native String nativeGetMediaStringMetadata(Medialibrary ml, long id, int metaDataType);
     private native void nativeSetMediaStringMetadata(Medialibrary ml, long id, int metaDataType, String metadataValue);
@@ -302,4 +311,5 @@ public class MediaWrapperImpl extends MediaWrapper {
     private native Bookmark nativeAddBookmark(Medialibrary ml, long id, long time);
     private native boolean nativeRemoveBookmark(Medialibrary ml, long id, long time);
     private native boolean nativeRemoveAllBookmarks(Medialibrary ml, long id);
+    private native boolean nativeMarkAsPlayed(Medialibrary ml, long id);
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java
index 5c429d4ff..179dcfadb 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java
@@ -128,4 +128,7 @@ public class StubMediaWrapper extends MediaWrapper {
         return true;
     }
 
+    @Override
+    public boolean markAsPlayed() { return true; }
+
 }



More information about the Android mailing list