[Android] Update to match new Medialibrary streams API

Geoffrey Métais git at videolan.org
Mon Jul 30 12:02:47 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jul 30 12:01:51 2018 +0200| [9dc095d0dcbbdcb0dfc46944a2f61624bbfdc966] | committer: Geoffrey Métais

Update to match new Medialibrary streams API

> https://code.videolan.org/videolan/vlc-android/commit/9dc095d0dcbbdcb0dfc46944a2f61624bbfdc966
---

 medialibrary/jni/AndroidMediaLibrary.cpp                     |  9 ++++++++-
 medialibrary/jni/AndroidMediaLibrary.h                       |  1 +
 medialibrary/jni/medialibrary.cpp                            | 12 ++++++++++++
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java |  8 ++++++++
 4 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index eaef0e756..45c645035 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -250,13 +250,20 @@ AndroidMediaLibrary::media(const std::string& mrl)
     return p_ml->media(mrl);
 }
 
-
 medialibrary::MediaPtr
 AndroidMediaLibrary::addMedia(const std::string& mrl)
 {
     return p_ml->addExternalMedia(mrl);
 }
 
+medialibrary::MediaPtr
+AndroidMediaLibrary::addStream(const std::string& mrl, const std::string& title)
+{
+    auto media = p_ml->addStream(mrl);
+    if (media != nullptr) media->setTitle(title);
+    return media;
+}
+
 std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::videoFiles( const medialibrary::QueryParameters* params )
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index cce459156..398eee166 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -63,6 +63,7 @@ public:
     medialibrary::MediaPtr media(long id);
     medialibrary::MediaPtr media(const std::string& mrl);
     medialibrary::MediaPtr addMedia(const std::string& mrl);
+    medialibrary::MediaPtr addStream(const std::string& mrl, const std::string& title);
     std::vector<medialibrary::MediaPtr> videoFiles( const medialibrary::QueryParameters* params = nullptr );
     std::vector<medialibrary::MediaPtr> audioFiles( const medialibrary::QueryParameters* params = nullptr );
     std::vector<medialibrary::AlbumPtr> albums(const medialibrary::QueryParameters* params);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 12999eaf9..3f80a0d44 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -470,6 +470,17 @@ addMedia(JNIEnv* env, jobject thiz, jstring mrl) {
     return mw;
 }
 
+jobject
+addStream(JNIEnv* env, jobject thiz, jstring mrl, jstring title) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    const char *char_mrl = env->GetStringUTFChars(mrl, JNI_FALSE);
+    const char *char_title = env->GetStringUTFChars(title, JNI_FALSE);
+    jobject mw = mediaToMediaWrapper(env, &ml_fields, aml->addStream(char_mrl, char_title));
+    env->ReleaseStringUTFChars(mrl, char_mrl);
+    env->ReleaseStringUTFChars(title, char_title);
+    return mw;
+}
+
 jobjectArray
 getAlbums(JNIEnv* env, jobject thiz, jint sortingCriteria, jboolean desc)
 {
@@ -890,6 +901,7 @@ static JNINativeMethod methods[] = {
     {"nativeGetMedia", "(J)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMedia },
     {"nativeGetMediaFromMrl", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getMediaFromMrl },
     {"nativeAddMedia", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)addMedia },
+    {"nativeAddStream", "(Ljava/lang/String;Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)addStream },
     {"nativeGetVideoCount", "()I", (void*)getVideoCount },
     {"nativeGetAudioCount", "()I", (void*)getAudioCount },
     {"nativeGetAlbums", "(IZ)[Lorg/videolan/medialibrary/media/Album;", (void*)getAlbums },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 9258b6ccb..4620e4a3b 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -345,6 +345,13 @@ public class Medialibrary {
         return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl) : null;
     }
 
+    @Nullable
+    public MediaWrapper addStream(String mrl, String title) {
+        final String vlcMrl = Tools.encodeVLCMrl(mrl);
+        final String vlcTitle = Tools.encodeVLCMrl(title);
+        return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddStream(vlcMrl, vlcTitle) : null;
+    }
+
     public void requestThumbnail(long id) {
         if (mIsInitiated) nativeRequestThumbnail(id);
     }
@@ -711,6 +718,7 @@ public class Medialibrary {
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
     private native MediaWrapper nativeAddMedia(String mrl);
+    private native MediaWrapper nativeAddStream(String mrl, String title);
     private native MediaWrapper[] nativeGetVideos();
     private native MediaWrapper[] nativeGetSortedVideos(int sort, boolean desc);
     private native MediaWrapper[] nativeGetRecentVideos();



More information about the Android mailing list