[Android] Pass libvlc instance to the ML
Nicolas Pomepuy
git at videolan.org
Thu Jun 10 09:42:20 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Mar 10 13:42:00 2021 +0100| [5c85995b87e8eadafea2f344f0a178ea95f543d9] | committer: Nicolas Pomepuy
Pass libvlc instance to the ML
> https://code.videolan.org/videolan/vlc-android/commit/5c85995b87e8eadafea2f344f0a178ea95f543d9
---
.../vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 2 ++
libvlc/src/org/videolan/libvlc/VLCObject.java | 8 ++++++--
medialibrary/jni/medialibrary.cpp | 6 ++++++
medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java | 6 ++++++
.../src/org/videolan/medialibrary/interfaces/Medialibrary.java | 1 +
.../src/org/videolan/medialibrary/stubs/StubMedialibrary.java | 3 +++
6 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index adcd22b3a..c9c284271 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -43,6 +43,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.channels.actor
import org.videolan.libvlc.util.AndroidUtil
+import org.videolan.libvlc.LibVLC
import org.videolan.medialibrary.MLServiceLocator
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb
import org.videolan.medialibrary.interfaces.Medialibrary
@@ -453,6 +454,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
val context = this at MediaParsingService
var shouldInit = !dbExists()
val initCode = medialibrary.init(context)
+ medialibrary.setLibVLCInstance((VLCInstance.getInstance(context) as LibVLC).getInstance())
medialibrary.setDiscoverNetworkEnabled(true)
if (initCode != Medialibrary.ML_INIT_ALREADY_INITIALIZED) {
shouldInit = shouldInit or (initCode == Medialibrary.ML_INIT_DB_RESET) or (initCode == Medialibrary.ML_INIT_DB_CORRUPTED)
diff --git a/libvlc/src/org/videolan/libvlc/VLCObject.java b/libvlc/src/org/videolan/libvlc/VLCObject.java
index 797c0c335..582092f54 100644
--- a/libvlc/src/org/videolan/libvlc/VLCObject.java
+++ b/libvlc/src/org/videolan/libvlc/VLCObject.java
@@ -23,14 +23,14 @@ package org.videolan.libvlc;
import android.os.Handler;
import android.os.Looper;
-import java.lang.ref.WeakReference;
-
import androidx.annotation.Nullable;
import org.videolan.libvlc.interfaces.AbstractVLCEvent;
import org.videolan.libvlc.interfaces.ILibVLC;
import org.videolan.libvlc.interfaces.IVLCObject;
+import java.lang.ref.WeakReference;
+
@SuppressWarnings("JniMissingFunction")
abstract class VLCObject<T extends AbstractVLCEvent> implements IVLCObject<T> {
private AbstractVLCEvent.Listener<T> mEventListener = null;
@@ -191,4 +191,8 @@ abstract class VLCObject<T extends AbstractVLCEvent> implements IVLCObject<T> {
if (obj != null)
obj.dispatchEventFromNative(eventType, arg1, arg2, argf1, args1);
}
+
+ public long getInstance() {
+ return mInstance;
+ }
}
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index d2a34e6f4..f5b7333b6 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -155,6 +155,11 @@ setDiscoverNetworkEnabled(JNIEnv* env, jobject thiz, jboolean enabled)
return aml->setDiscoverNetworkEnabled(enabled);
}
+void
+setLibVLCInstance(JNIEnv* env, jobject thiz, jlong libVLC){
+ //todo
+}
+
void
removeEntryPoint(JNIEnv* env, jobject thiz, jstring storagePath)
{
@@ -2020,6 +2025,7 @@ static JNINativeMethod methods[] = {
{"nativeDeleteRemovableDevices", "()Z", (void*)deleteRemovableDevices },
{"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
{"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
+ {"nativeSetLibVLCInstance", "(J)V", (void*)setLibVLCInstance },
{"nativeSetDiscoverNetworkEnabled", "(Z)Z", (void*)setDiscoverNetworkEnabled },
{"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
{"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index d898b64f3..c50303c87 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -136,6 +136,11 @@ public class MedialibraryImpl extends Medialibrary {
if (mIsInitiated) nativeDiscover(Tools.encodeVLCMrl(path));
}
+ @Override
+ public void setLibVLCInstance(long libVLC) {
+ if (mIsInitiated) nativeSetLibVLCInstance(libVLC);
+ }
+
@Override
public boolean setDiscoverNetworkEnabled(boolean enabled) {
if (mIsInitiated) return nativeSetDiscoverNetworkEnabled(enabled);
@@ -590,6 +595,7 @@ public class MedialibraryImpl extends Medialibrary {
private native boolean nativeDeleteRemovableDevices();
private native String[] nativeDevices();
private native void nativeDiscover(String path);
+ private native void nativeSetLibVLCInstance(long libVLC);
private native boolean nativeSetDiscoverNetworkEnabled(boolean enabled);
private native void nativeRemoveEntryPoint(String path);
private native String[] nativeEntryPoints();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index a388bf0cf..e3984e78f 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -679,6 +679,7 @@ abstract public class Medialibrary {
abstract public boolean isDeviceKnown(@NonNull String uuid, @NonNull String path, boolean removable);
abstract public boolean deleteRemovableDevices();
abstract public void discover(@NonNull String path);
+ abstract public void setLibVLCInstance(long libVLC);
abstract public boolean setDiscoverNetworkEnabled(boolean enabled);
abstract public void removeFolder(@NonNull String mrl);
abstract public String[] getFoldersList();
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index 947ed7260..4ac453737 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -83,6 +83,9 @@ public class StubMedialibrary extends Medialibrary {
onBackgroundTasksIdleChanged(true);
}
+ @Override
+ public void setLibVLCInstance(long libVLC) { }
+
@Override
public boolean setDiscoverNetworkEnabled(boolean enabled) {
return false;
More information about the Android
mailing list