[Android] Add addMedia method for external media

Geoffrey Métais git at videolan.org
Tue Jan 3 17:13:06 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan  3 13:58:00 2017 +0100| [4323a4b0a8e11891eda855cb42a916f633cdd52e] | committer: Geoffrey Métais

Add addMedia method for external media

> https://code.videolan.org/videolan/vlc-android/commit/4323a4b0a8e11891eda855cb42a916f633cdd52e
---

 medialibrary/jni/AndroidMediaLibrary.cpp                     |  7 +++++++
 medialibrary/jni/AndroidMediaLibrary.h                       |  1 +
 medialibrary/jni/medialibrary.cpp                            | 10 ++++++++++
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java |  5 +++++
 4 files changed, 23 insertions(+)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 862144c..e11a4d2 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -218,6 +218,13 @@ AndroidMediaLibrary::media(const std::string& mrl)
     return p_ml->media(mrl);
 }
 
+
+medialibrary::MediaPtr
+AndroidMediaLibrary::addMedia(const std::string& mrl)
+{
+    return p_ml->addMedia(mrl);
+}
+
 std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::videoFiles( medialibrary::SortingCriteria sort, bool desc )
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 45dfa73..5ca3d27 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -54,6 +54,7 @@ public:
     medialibrary::SearchAggregate search(const std::string& query);
     medialibrary::MediaPtr media(long id);
     medialibrary::MediaPtr media(const std::string& mrl);
+    medialibrary::MediaPtr addMedia(const std::string& mrl);
     std::vector<medialibrary::MediaPtr> videoFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false );
     std::vector<medialibrary::MediaPtr> audioFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false );
     std::vector<medialibrary::AlbumPtr> albums();
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index ea9b097..14a92a1 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -303,6 +303,15 @@ getMediaFromMrl(JNIEnv* env, jobject thiz, jstring mrl) {
     return mw;
 }
 
+jobject
+addMedia(JNIEnv* env, jobject thiz, jstring mrl) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    const char *char_mrl = env->GetStringUTFChars(mrl, JNI_FALSE);
+    jobject mw = mediaToMediaWrapper(env, &ml_fields, aml->addMedia(char_mrl));
+    env->ReleaseStringUTFChars(mrl, char_mrl);
+    return mw;
+}
+
 jobjectArray
 getAlbums(JNIEnv* env, jobject thiz)
 {
@@ -609,6 +618,7 @@ static JNINativeMethod methods[] = {
     {"nativeSearch", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/SearchAggregate;", (void*)search},
     {"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 },
     {"nativeGetVideoCount", "()I", (void*)getVideoCount },
     {"nativeGetAudioCount", "()I", (void*)getAudioCount },
     {"nativeGetAlbums", "()[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 27c506d..93b1fda 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -205,6 +205,10 @@ public class Medialibrary {
         return mIsInitiated ? nativeGetMediaFromMrl(mrl) : null;
     }
 
+    public MediaWrapper addMedia(String mrl) {
+        return nativeAddMedia(mrl);
+    }
+
     public long getId() {
         return mInstanceID;
     }
@@ -433,6 +437,7 @@ public class Medialibrary {
     private native  boolean nativeClearHistory();
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
+    private native MediaWrapper nativeAddMedia(String mrl);
     private native MediaWrapper[] nativeGetVideos();
     private native MediaWrapper[] nativeGetAudio();
     private native int nativeGetVideoCount();



More information about the Android mailing list