[Android] Manual groups JNI

Nicolas Pomepuy git at videolan.org
Thu Apr 16 10:25:56 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Apr 15 14:32:06 2020 +0200| [10d7e783f257b75e6105eebe3965f4d0004bdc7c] | committer: Geoffrey Métais

Manual groups JNI

> https://code.videolan.org/videolan/vlc-android/commit/10d7e783f257b75e6105eebe3965f4d0004bdc7c
---

 medialibrary/jni/AndroidMediaLibrary.cpp           | 12 ++++++++++
 medialibrary/jni/AndroidMediaLibrary.h             |  2 ++
 medialibrary/jni/medialibrary.cpp                  | 26 ++++++++++++++++++++++
 .../videolan/medialibrary/MedialibraryImpl.java    | 16 +++++++++++++
 .../medialibrary/interfaces/Medialibrary.java      |  4 ++++
 .../medialibrary/stubs/StubMedialibrary.java       | 10 +++++++++
 6 files changed, 70 insertions(+)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 95a909eb4..610c3cfc9 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -584,6 +584,18 @@ AndroidMediaLibrary::groupDestroy( const int64_t groupId )
     return group != nullptr && group->destroy();
 }
 
+medialibrary::MediaGroupPtr
+AndroidMediaLibrary::createMediaGroup( std::string name )
+{
+    return p_ml->createMediaGroup(name);
+}
+
+medialibrary::MediaGroupPtr
+AndroidMediaLibrary::createMediaGroup( const std::vector<int64_t> mediaIds )
+{
+    return p_ml->createMediaGroup(mediaIds);
+}
+
 void
 AndroidMediaLibrary::requestThumbnail( int64_t media_id, medialibrary::ThumbnailSizeType sizeType, uint32_t desiredWidth,
                                        uint32_t desiredHeight, float position )
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 959aa62c7..b2b557e92 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -113,6 +113,8 @@ public:
     bool groupUserInteracted(const int64_t groupId );
     int64_t groupDuration(const int64_t groupId );
     bool groupDestroy(const int64_t groupId );
+    medialibrary::MediaGroupPtr createMediaGroup( std::string name );
+    medialibrary::MediaGroupPtr createMediaGroup( std::vector<int64_t> mediaIds );
     void onMediaGroupsModified( std::set<int64_t> mediaGroupsIds );
     void onMediaGroupsDeleted( std::set<int64_t> mediaGroupsIds );
     void onBookmarksAdded( std::vector<medialibrary::BookmarkPtr> );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index ebb43341e..1acbbb187 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1909,6 +1909,30 @@ groupDestroy(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
     return MediaLibrary_getInstance(env, medialibrary)->groupDestroy(id);
 }
 
+jobject
+createMediaGroupByName(JNIEnv* env, jobject thiz, jstring name)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    const char *name_cstr = env->GetStringUTFChars(name, JNI_FALSE);
+    medialibrary::MediaGroupPtr group = aml->createMediaGroup(name_cstr);
+    env->ReleaseStringUTFChars(name, name_cstr);
+    return group != nullptr ? convertVideoGroupObject(env, &ml_fields, group) : nullptr;
+}
+
+jobject
+createMediaGroup(JNIEnv* env, jobject thiz, jlongArray mediaIds)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    std::vector<int64_t> cids;
+    jsize size = env->GetArrayLength(mediaIds);
+    jlong *ids = env->GetLongArrayElements(mediaIds, 0);
+    for (int i = 0; i < size; ++i)
+        cids.push_back((int64_t) ids[i]);
+    env->ReleaseLongArrayElements(mediaIds, ids, 0);
+    medialibrary::MediaGroupPtr group = aml->createMediaGroup(cids);
+    return group != nullptr ? convertVideoGroupObject(env, &ml_fields, group) : nullptr;
+}
+
  /*
   * JNI stuff
   */
@@ -1994,6 +2018,8 @@ static JNINativeMethod methods[] = {
     {"nativePlaylistCreate", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/Playlist;", (void*)playlistCreate },
     {"nativeGetVideoGroups", "(IZII)[Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)videoGroups },
     {"nativeGetVideoGroupsCount", "()I", (void*)videoGroupsCount },
+    {"nativeCreateGroupByName", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)createMediaGroupByName },
+    {"nativeCreateGroup", "([J)Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)createMediaGroup },
 
 };
 
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index 6a9f3b069..878f3c872 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -228,6 +228,18 @@ public class MedialibraryImpl extends Medialibrary {
         if (mIsInitiated) nativeSetVideoGroupsPrefixLength(lenght);
     }
 
+    @Override
+    @WorkerThread
+    public VideoGroup createVideoGroup(String name) {
+        return mIsInitiated && !TextUtils.isEmpty(name) ? nativeCreateGroupByName(name) : null;
+    }
+
+    @Override
+    @WorkerThread
+    public VideoGroup createVideoGroup(long[] ids) {
+        return mIsInitiated && (ids.length != 0) ? nativeCreateGroup(ids) : null;
+    }
+
 
     @WorkerThread
     public Album[] getAlbums() {
@@ -563,6 +575,10 @@ public class MedialibraryImpl extends Medialibrary {
     private native VideoGroup[] nativeGetVideoGroups(int sort, boolean desc, int nbItems, int offset);
     private native int nativeGetVideoGroupsCount();
     private native void nativeSetVideoGroupsPrefixLength(int length);
+
+    private native VideoGroup nativeCreateGroupByName(String name);
+
+    private native VideoGroup nativeCreateGroup(long[] ids);
     private native Album[] nativeGetAlbums(int sort, boolean desc);
     private native Album[] nativeGetPagedAlbums(int sort, boolean desc, int nbItems, int offset);
     private native int nativeGetAlbumsCount();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index da0276ab4..d07ebfe71 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -714,6 +714,10 @@ abstract public class Medialibrary {
     abstract public VideoGroup[] getVideoGroups(int sort, boolean desc, int nbItems, int offset);
     abstract public int getVideoGroupsCount();
     abstract public void setVideoGroupsPrefixLength(int lenght);
+
+    abstract public VideoGroup createVideoGroup(String name);
+
+    abstract public VideoGroup createVideoGroup(long[] ids);
     abstract public Album[] getAlbums();
     abstract public Album[] getAlbums(int sort, boolean desc);
     abstract public Album[] getPagedAlbums(int sort, boolean desc, int nbItems, int offset);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index 20f460d7f..0ffc172bd 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -148,6 +148,16 @@ public class StubMedialibrary extends Medialibrary {
     @Override
     public void setVideoGroupsPrefixLength(int lenght) {}
 
+    @Override
+    public VideoGroup createVideoGroup(String name) {
+        return null;
+    }
+
+    @Override
+    public VideoGroup createVideoGroup(long[] ids) {
+        return null;
+    }
+
     public Album[] getAlbums() {
         return getAlbums(SORT_DEFAULT, false);
     }



More information about the Android mailing list