[Android] Medialibrary: add getter for media playCount
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> | Mon May 2 11:30:53 2022 +0200| [0163bb2b41f59f4be026b2495149a2997514b1e4] | committer: Duncan McNamara
Medialibrary: add getter for media playCount
> https://code.videolan.org/videolan/vlc-android/commit/0163bb2b41f59f4be026b2495149a2997514b1e4
---
medialibrary/jni/medialibrary.cpp | 10 ++++++++++
.../videolan/medialibrary/interfaces/media/MediaWrapper.java | 1 +
.../src/org/videolan/medialibrary/media/MediaWrapperImpl.java | 8 ++++++++
.../src/org/videolan/medialibrary/stubs/StubMediaWrapper.java | 5 +++++
4 files changed, 24 insertions(+)
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index bf5fa223e..dd4daf027 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1531,6 +1531,15 @@ setMediaPlayCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jlo
return media->setPlayCount(playCount);
}
+jlong
+getMediaPlayCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
+{
+ AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
+ medialibrary::MediaPtr media = aml->media(id);
+ if (media == nullptr) return -1;
+ return media->playCount();
+}
+
jboolean
removeMediaThumbnail(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
{
@@ -2124,6 +2133,7 @@ static JNINativeMethod media_methods[] = {
{"nativeSetMediaLongMetadata", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JIJ)V", (void*)setMediaLongMetadata },
{"nativeSetMediaThumbnail", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JLjava/lang/String;)V", (void*)setMediaThumbnail },
{"nativeSetMediaPlayCount", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JJ)Z", (void*)setMediaPlayCount },
+ {"nativeGetMediaPlayCount", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)J", (void*)getMediaPlayCount },
{"nativeRemoveMediaThumbnail", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Z", (void*)removeMediaThumbnail },
{"nativeSetMediaTitle", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;JLjava/lang/String;)V", (void*)setMediaTitle },
{"nativeRemoveFromHistory", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;J)Z", (void*)removeMediaFromHistory },
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
index a4558b13d..2e02001da 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -133,6 +133,7 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
public abstract boolean setStringMeta(int metaDataType, String metaDataValue);
public abstract void setThumbnail(String mrl);
public abstract boolean setPlayCount(long playCount);
+ public abstract long getPlayCount();
public abstract void removeThumbnail();
public abstract void requestThumbnail(int width, float position);
public abstract void requestBanner(int width, float position);
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
index 26bc1bcb9..87b3e6d18 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapperImpl.java
@@ -262,6 +262,13 @@ public class MediaWrapperImpl extends MediaWrapper {
return nativeSetMediaPlayCount(ml, mId, playCount);
}
+ @Override
+ public long getPlayCount() {
+ if (mId == 0L) return -1;
+ final Medialibrary ml = Medialibrary.getInstance();
+ return nativeGetMediaPlayCount(ml, mId);
+ }
+
public void removeThumbnail() {
if (mId == 0L) return;
final Medialibrary ml = Medialibrary.getInstance();
@@ -288,6 +295,7 @@ public class MediaWrapperImpl extends MediaWrapper {
private native boolean nativeRemoveFromHistory(Medialibrary ml, long id);
private native void nativeSetMediaThumbnail(Medialibrary ml, long id, String mrl);
private native boolean nativeSetMediaPlayCount(Medialibrary ml, long id, long playCount);
+ private native long nativeGetMediaPlayCount(Medialibrary ml, long id);
private native boolean nativeRemoveMediaThumbnail(Medialibrary ml, long id);
private native void nativeRequestThumbnail(Medialibrary ml, long mediaId, int type, int width, int height, float position);
private native Bookmark[] nativeGetBookmarks(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 57df19b13..5c429d4ff 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMediaWrapper.java
@@ -108,6 +108,11 @@ public class StubMediaWrapper extends MediaWrapper {
return true;
}
+ @Override
+ public long getPlayCount() {
+ return 1;
+ }
+
public void removeThumbnail() {}
@Override
More information about the Android
mailing list