[Android] Implement medialibrary setDiscoverNetworkEnabled
Nicolas Pomepuy
git at videolan.org
Thu Jun 10 06:17:24 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jan 21 14:40:08 2021 +0100| [46b7b6c87a7a1b7167383bb917aa88e57d5f047b] | committer: Nicolas Pomepuy
Implement medialibrary setDiscoverNetworkEnabled
> https://code.videolan.org/videolan/vlc-android/commit/46b7b6c87a7a1b7167383bb917aa88e57d5f047b
---
.../vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 1 +
medialibrary/jni/AndroidMediaLibrary.cpp | 9 +++++++++
medialibrary/jni/AndroidMediaLibrary.h | 1 +
medialibrary/jni/medialibrary.cpp | 8 ++++++++
medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java | 7 +++++++
.../src/org/videolan/medialibrary/interfaces/Medialibrary.java | 1 +
.../src/org/videolan/medialibrary/stubs/StubMedialibrary.java | 6 ++++++
7 files changed, 33 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index b590f895f..adcd22b3a 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -453,6 +453,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
val context = this at MediaParsingService
var shouldInit = !dbExists()
val initCode = medialibrary.init(context)
+ 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)
if (initCode != Medialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade, action.removeDevices)
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index fc626164b..4c52c5278 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -115,6 +115,12 @@ AndroidMediaLibrary::discover(const std::string& libraryPath)
p_ml->discover(libraryPath);
}
+bool
+AndroidMediaLibrary::setDiscoverNetworkEnabled(bool enabled)
+{
+ return p_ml->setDiscoverNetworkEnabled(enabled);
+}
+
void
AndroidMediaLibrary::removeEntryPoint(const std::string& entryPoint)
{
@@ -908,6 +914,9 @@ void AndroidMediaLibrary::onDiscoveryCompleted( const std::string& entryPoint, b
env->CallVoidMethod(weak_thiz, p_fields->MediaLibrary.onParsingStatsUpdatedId, m_progress);
env->CallVoidMethod(weak_thiz, p_fields->MediaLibrary.onDiscoveryCompletedId, ep);
}
+ if (!success) {
+ LOGE("onDiscoveryCompleted -> ko");
+ }
env->DeleteLocalRef(ep);
}
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index d260bf194..b2120a54f 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -41,6 +41,7 @@ public:
void banFolder(const std::string& path);
void unbanFolder(const std::string& path);
void discover(const std::string&);
+ bool setDiscoverNetworkEnabled(bool enabled);
void removeEntryPoint(const std::string& entryPoint);
std::vector<medialibrary::FolderPtr> entryPoints();
void setMediaUpdatedCbFlag(int flags);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 4520b6e92..80af6a2b1 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -134,6 +134,13 @@ discover(JNIEnv* env, jobject thiz, jstring storagePath)
env->ReleaseStringUTFChars(storagePath, path);
}
+jboolean
+setDiscoverNetworkEnabled(JNIEnv* env, jobject thiz, jboolean enabled)
+{
+ AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+ return aml->setDiscoverNetworkEnabled(enabled);
+}
+
void
removeEntryPoint(JNIEnv* env, jobject thiz, jstring storagePath)
{
@@ -2138,6 +2145,7 @@ static JNINativeMethod methods[] = {
{"nativeDeleteRemovableDevices", "()Z", (void*)deleteRemovableDevices },
{"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
{"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
+ {"nativeSetDiscoverNetworkEnabled", "(Z)Z", (void*)setDiscoverNetworkEnabled },
{"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
{"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
{"nativeRemoveDevice", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)removeDevice },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index 146c5d19c..4f48336d8 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -136,6 +136,12 @@ public class MedialibraryImpl extends Medialibrary {
if (mIsInitiated) nativeDiscover(Tools.encodeVLCMrl(path));
}
+ @Override
+ public boolean setDiscoverNetworkEnabled(boolean enabled) {
+ if (mIsInitiated) return nativeSetDiscoverNetworkEnabled(enabled);
+ return false;
+ }
+
public void removeFolder(@NonNull String mrl) {
if (!mIsInitiated) return;
final String[] folders = getFoldersList();
@@ -584,6 +590,7 @@ public class MedialibraryImpl extends Medialibrary {
private native boolean nativeDeleteRemovableDevices();
private native String[] nativeDevices();
private native void nativeDiscover(String path);
+ private native boolean nativeSetDiscoverNetworkEnabled(boolean enabled);
private native void nativeRemoveEntryPoint(String path);
private native String[] nativeEntryPoints();
private native boolean nativeRemoveDevice(String uuid, String path);
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index eec0bb3e2..be453dcc3 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 boolean setDiscoverNetworkEnabled(boolean enabled);
abstract public void removeFolder(@NonNull String mrl);
abstract public String[] getFoldersList();
abstract public boolean removeDevice(String uuid, String path);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index bb6d2fccb..5e4104c0e 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -82,6 +82,12 @@ public class StubMedialibrary extends Medialibrary {
onDiscoveryCompleted(path);
onBackgroundTasksIdleChanged(true);
}
+
+ @Override
+ public boolean setDiscoverNetworkEnabled(boolean enabled) {
+ return false;
+ }
+
public void removeFolder(@NonNull String mrl) {}
public boolean removeDevice(String uuid, String path) {
More information about the Android
mailing list