[Android] Medialibrary: Add ext media removal

Geoffrey Métais git at videolan.org
Tue Apr 2 16:59:47 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 11 09:59:30 2019 +0100| [b16517b14fe1fd8795cb0d78991457c37075af68] | committer: Geoffrey Métais

Medialibrary: Add ext media removal

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

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

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index cfc41270f..9085bc582 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -311,6 +311,13 @@ AndroidMediaLibrary::addMedia(const std::string& mrl)
     return p_ml->addExternalMedia(mrl);
 }
 
+bool
+AndroidMediaLibrary::removeExternalMedia(long id)
+{
+    auto media = p_ml->media(id);
+    return media != nullptr && p_ml->removeExternalMedia(media);
+}
+
 medialibrary::MediaPtr
 AndroidMediaLibrary::addStream(const std::string& mrl, const std::string& title)
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 035c2c0a9..f4b12a4a9 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -72,6 +72,7 @@ public:
     medialibrary::MediaPtr media(long id);
     medialibrary::MediaPtr media(const std::string& mrl);
     medialibrary::MediaPtr addMedia(const std::string& mrl);
+    bool removeExternalMedia(long id);
     medialibrary::MediaPtr addStream(const std::string& mrl, const std::string& title);
     medialibrary::Query<medialibrary::IMedia> videoFiles( const medialibrary::QueryParameters* params = nullptr );
     medialibrary::Query<medialibrary::IMedia> audioFiles( const medialibrary::QueryParameters* params = nullptr );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index f4bd2f2f5..0ad82a760 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -695,6 +695,12 @@ addMedia(JNIEnv* env, jobject thiz, jstring mrl) {
     return mw;
 }
 
+jboolean
+removeExternalMedia(JNIEnv* env, jobject thiz, jlong id) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    return aml->removeExternalMedia(id);
+}
+
 jobject
 addStream(JNIEnv* env, jobject thiz, jstring mrl, jstring title) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
@@ -1716,6 +1722,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 },
+    {"nativeRemoveExternalMedia", "(J)Z", (void*)removeExternalMedia },
     {"nativeAddStream", "(Ljava/lang/String;Ljava/lang/String;)Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)addStream },
     {"nativeGetVideoCount", "()I", (void*)getVideoCount },
     {"nativeGetAudioCount", "()I", (void*)getAudioCount },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index f887db8c8..bbaf3c41d 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -444,6 +444,10 @@ public class Medialibrary {
         return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl) : null;
     }
 
+    public boolean removeExternalMedia(long id) {
+        return mIsInitiated && nativeRemoveExternalMedia(id);
+    }
+
     @Nullable
     public MediaWrapper addStream(String mrl, String title) {
         final String vlcMrl = Tools.encodeVLCMrl(mrl);
@@ -969,6 +973,7 @@ public class Medialibrary {
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
     private native MediaWrapper nativeAddMedia(String mrl);
+    private native boolean nativeRemoveExternalMedia(long id);
     private native MediaWrapper nativeAddStream(String mrl, String title);
     private native MediaWrapper[] nativeGetVideos();
     private native MediaWrapper[] nativeGetSortedVideos(int sort, boolean desc);



More information about the Android mailing list