[Android] Update Medialibrary method to check if scanning
Geoffrey Métais
git at videolan.org
Fri May 12 18:14:23 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 12 18:13:17 2017 +0200| [a9da204aadb4655e37836169f0211ac80394da11] | committer: Geoffrey Métais
Update Medialibrary method to check if scanning
> https://code.videolan.org/videolan/vlc-android/commit/a9da204aadb4655e37836169f0211ac80394da11
---
compile-libvlc.sh | 2 +-
medialibrary/jni/AndroidMediaLibrary.cpp | 21 +++++++++++++++------
medialibrary/jni/AndroidMediaLibrary.h | 2 +-
medialibrary/jni/medialibrary.cpp | 12 ++++--------
medialibrary/jni/utils.h | 1 +
.../src/org/videolan/medialibrary/Medialibrary.java | 16 ++++++++++++----
.../src/org/videolan/vlc/VLCApplication.java | 2 +-
7 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/compile-libvlc.sh b/compile-libvlc.sh
index 2b6a1a4..4715881 100755
--- a/compile-libvlc.sh
+++ b/compile-libvlc.sh
@@ -16,7 +16,7 @@ checkfail()
# ARGUMENTS #
#############
-MEDIALIBRARY_HASH=1b6ac171
+MEDIALIBRARY_HASH=a490aec
RELEASE=0
ASAN=0
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 87b293a..c38381e 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -113,12 +113,6 @@ AndroidMediaLibrary::entryPoints()
return p_ml->entryPoints();
}
-bool
-AndroidMediaLibrary::isWorking()
-{
- return !m_paused && (m_nbDiscovery > 0 || (m_progress > 0 && m_progress < 100));
-}
-
void
AndroidMediaLibrary::pauseBackgroundOperations()
{
@@ -759,6 +753,21 @@ void AndroidMediaLibrary::onParsingStatsUpdated( uint32_t percent)
}
}
+
+void AndroidMediaLibrary::onBackgroundTasksIdleChanged( bool isIdle )
+{
+ JNIEnv *env = getEnv();
+ if (env == NULL)
+ return;
+ jobject thiz = getWeakReference(env);
+ if (thiz != NULL)
+ {
+ env->CallVoidMethod(thiz, p_fields->MediaLibrary.onBackgroundTasksIdleChangedId, isIdle);
+ if (weak_compat)
+ env->DeleteLocalRef(thiz);
+ }
+}
+
jobject
AndroidMediaLibrary::getWeakReference(JNIEnv *env)
{
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 0f24c4b..96b1e0e 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -37,7 +37,6 @@ public:
void discover(const std::string&);
void removeEntryPoint(const std::string& entryPoint);
std::vector<medialibrary::FolderPtr> entryPoints();
- bool isWorking();
void setMediaUpdatedCbFlag(int flags);
void setMediaAddedCbFlag(int flags);
void pauseBackgroundOperations();
@@ -114,6 +113,7 @@ public:
void onEntryPointUnbanned( const std::string& entryPoint, bool success );
void onEntryPointRemoved( const std::string& entryPoint, bool success );
void onParsingStatsUpdated( uint32_t percent);
+ void onBackgroundTasksIdleChanged( bool isIdle );
private:
void jni_detach_thread(void *data);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index e54249b..da9701f 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -135,13 +135,6 @@ removeDevice(JNIEnv* env, jobject thiz, jstring uuid)
return removed;
}
-jboolean
-isWorking(JNIEnv* env, jobject thiz)
-{
- AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
- return (jboolean) aml->isWorking();
-}
-
void
setMediaUpdatedCbFlag(JNIEnv* env, jobject thiz, jint flags)
{
@@ -785,7 +778,6 @@ static JNINativeMethod methods[] = {
{"nativeGetGenre", "(J)Lorg/videolan/medialibrary/media/Genre;", (void*)getGenre },
{"nativeGetPlaylists", "()[Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylists },
{"nativeGetPlaylist", "(J)Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylist },
- {"nativeIsWorking", "()Z", (void*)isWorking },
{"nativePauseBackgroundOperations", "()V", (void*)pauseBackgroundOperations },
{"nativeResumeBackgroundOperations", "()V", (void*)resumeBackgroundOperations },
{"nativeReload", "()V", (void*)reload },
@@ -1046,6 +1038,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
ml_fields.MediaLibrary.clazz,
"onParsingStatsUpdated", "(I)V");
GET_ID(GetMethodID,
+ ml_fields.MediaLibrary.onBackgroundTasksIdleChangedId,
+ ml_fields.MediaLibrary.clazz,
+ "onBackgroundTasksIdleChanged", "(Z)V");
+ GET_ID(GetMethodID,
ml_fields.MediaLibrary.onReloadStartedId,
ml_fields.MediaLibrary.clazz,
"onReloadStarted", "(Ljava/lang/String;)V");
diff --git a/medialibrary/jni/utils.h b/medialibrary/jni/utils.h
index fb247e8..3165a03 100644
--- a/medialibrary/jni/utils.h
+++ b/medialibrary/jni/utils.h
@@ -53,6 +53,7 @@ struct fields {
jmethodID onDiscoveryProgressId;
jmethodID onDiscoveryCompletedId;
jmethodID onParsingStatsUpdatedId;
+ jmethodID onBackgroundTasksIdleChangedId;
jmethodID onReloadStartedId;
jmethodID onReloadCompletedId;
jmethodID onEntryPointBannedId;
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index b7aef30..82b855d 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -46,8 +46,11 @@ public class Medialibrary {
public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
public static final String THUMBS_FOLDER_NAME = "/thumbs";
+ private Context mContext;
+
private long mInstanceID;
private volatile boolean mIsInitiated = false;
+ private boolean mIsWorking = false;
private MediaUpdatedCb mediaUpdatedCb = null;
private MediaAddedCb mediaAddedCb = null;
@@ -118,9 +121,11 @@ public class Medialibrary {
super.finalize();
}
- public static synchronized Medialibrary getInstance() {
- if (sInstance == null)
+ public static synchronized Medialibrary getInstance(Context context) {
+ if (sInstance == null) {
sInstance = new Medialibrary();
+ sInstance.mContext = context;
+ }
return sInstance;
}
@@ -242,7 +247,7 @@ public class Medialibrary {
}
public boolean isWorking() {
- return !mIsInitiated || nativeIsWorking();
+ return mIsWorking;
}
public boolean isInitiated() {
@@ -359,6 +364,10 @@ public class Medialibrary {
}
}
+ public void onBackgroundTasksIdleChanged(boolean isIdle) {
+ mIsWorking = !isIdle;
+ }
+
void onReloadStarted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
@@ -561,7 +570,6 @@ public class Medialibrary {
private native MediaWrapper[] nativeGetRecentAudio();
private native int nativeGetVideoCount();
private native int nativeGetAudioCount();
- private native boolean nativeIsWorking();
private native Album[] nativeGetAlbums();
private native Album nativeGetAlbum(long albumtId);
private native Artist[] nativeGetArtists();
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 3b2a916..aabd957 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -248,7 +248,7 @@ public class VLCApplication extends Application {
public static synchronized Medialibrary getMLInstance() {
if (sMedialibraryInstance == null) {
VLCInstance.get(); // ensure VLC is loaded before medialibrary
- sMedialibraryInstance = Medialibrary.getInstance();
+ sMedialibraryInstance = Medialibrary.getInstance(instance);
}
return sMedialibraryInstance;
}
More information about the Android
mailing list