[Android] fixup! Pass libvlc instance to the ML

Hugo Beauzée-Luyssen git at videolan.org
Thu Jun 10 06:17:25 UTC 2021


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Mar 12 15:20:58 2021 +0100| [e18cfd3756013fb7c61971b943cdb6ce4a24483b] | committer: Nicolas Pomepuy

fixup! Pass libvlc instance to the ML

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

 libvlc/jni/libvlcjni-vlcobject.c              | 9 +++++++++
 libvlc/src/org/videolan/libvlc/VLCObject.java | 4 +---
 medialibrary/jni/AndroidMediaLibrary.cpp      | 5 +++++
 medialibrary/jni/AndroidMediaLibrary.h        | 1 +
 medialibrary/jni/medialibrary.cpp             | 3 ++-
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libvlc/jni/libvlcjni-vlcobject.c b/libvlc/jni/libvlcjni-vlcobject.c
index 02ca8327b..5505404a9 100644
--- a/libvlc/jni/libvlcjni-vlcobject.c
+++ b/libvlc/jni/libvlcjni-vlcobject.c
@@ -226,3 +226,12 @@ Java_org_videolan_libvlc_VLCObject_nativeDetachEvents(JNIEnv *env, jobject thiz)
     p_obj->p_owner->p_event_manager = NULL;
     p_obj->p_owner->p_events = NULL;
 }
+
+long
+Java_org_videolan_libvlc_VLCObject_getInstance(JNIEnv *env, jobject thiz)
+{
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+    if (!p_obj)
+        return 0;
+    return p_obj->u.p_libvlc;
+}
diff --git a/libvlc/src/org/videolan/libvlc/VLCObject.java b/libvlc/src/org/videolan/libvlc/VLCObject.java
index 582092f54..f1eba092a 100644
--- a/libvlc/src/org/videolan/libvlc/VLCObject.java
+++ b/libvlc/src/org/videolan/libvlc/VLCObject.java
@@ -192,7 +192,5 @@ abstract class VLCObject<T extends AbstractVLCEvent> implements IVLCObject<T> {
             obj.dispatchEventFromNative(eventType, arg1, arg2, argf1, args1);
     }
 
-    public long getInstance() {
-        return mInstance;
-    }
+    public native long getInstance();
 }
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index ad52f2e53..b30529ff3 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -655,6 +655,11 @@ AndroidMediaLibrary::requestThumbnail( int64_t media_id, medialibrary::Thumbnail
     if (media != nullptr) media->requestThumbnail(sizeType, desiredWidth, desiredHeight, position);
 }
 
+void AndroidMediaLibrary::setLibvlcInstance( libvlc_instance_t* inst )
+{
+    p_ml->setExternalLibvlcInstance( inst );
+}
+
 void
 AndroidMediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> mediaList )
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 6dcc4f151..4b136f836 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -54,6 +54,7 @@ public:
     void forceRescan();
     bool setProgress(int64_t mediaId, float progress);
     bool removeMediaFromHistory(int64_t mediaId);
+    void setLibvlcInstance(libvlc_instance_t* inst);
     /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
     bool addToHistory( const std::string& mrl, const std::string& title );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index f5b7333b6..0fd6c9912 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -157,7 +157,8 @@ setDiscoverNetworkEnabled(JNIEnv* env, jobject thiz, jboolean enabled)
 
 void
 setLibVLCInstance(JNIEnv* env, jobject thiz, jlong libVLC){
-    //todo
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    aml->setLibvlcInstance( (libvlc_instance_t*)libVLC );
 }
 
 void



More information about the Android mailing list