[Android] Request thumbnail from ML when none found

Geoffrey Métais git at videolan.org
Wed Apr 4 18:35:34 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 20 17:06:29 2018 +0100| [829eabb6c56b7efaaa74d909b2b2a7be3373d51f] | committer: Geoffrey Métais

Request thumbnail from ML when none found

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

 medialibrary/jni/medialibrary.cpp                             | 8 ++++++++
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java  | 8 ++++++--
 vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java | 3 ++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 8340bc895..255101add 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -547,6 +547,13 @@ playlistCreate(JNIEnv* env, jobject thiz, jstring name)
     return playlist != nullptr ? convertPlaylistObject(env, &ml_fields, playlist) : nullptr;
 }
 
+void
+requestThumbnail(JNIEnv* env, jobject thiz, jlong mediaId)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    aml->requestThumbnail(mediaId);
+}
+
 /*
  * Album methods
  */
@@ -838,6 +845,7 @@ static JNINativeMethod methods[] = {
     {"nativeSetMediaUpdatedCbFlag", "(I)V", (void*)setMediaUpdatedCbFlag },
     {"nativeSetMediaAddedCbFlag", "(I)V", (void*)setMediaAddedCbFlag },
     {"nativePlaylistCreate", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/Playlist;", (void*)playlistCreate },
+    {"nativeRequestThumbnail", "(J)V", (void*)requestThumbnail },
 };
 
 static JNINativeMethod media_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 04db3ce91..4681a7b9d 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -285,8 +285,7 @@ public class Medialibrary {
     }
 
     public void reload() {
-        if (mIsInitiated && !isWorking())
-            nativeReload();
+        if (mIsInitiated && !isWorking()) nativeReload();
     }
 
     public void reload(String entryPoint) {
@@ -343,6 +342,10 @@ public class Medialibrary {
         return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl) : null;
     }
 
+    public void requestThumbnail(long id) {
+        if (mIsInitiated) nativeRequestThumbnail(id);
+    }
+
     public long getId() {
         return mInstanceID;
     }
@@ -737,6 +740,7 @@ public class Medialibrary {
     private native Album[] nativeSearchAlbum(String query);
     private native Genre[] nativeSearchGenre(String query);
     private native Playlist[] nativeSearchPlaylist(String query);
+    private native void nativeRequestThumbnail(long mediaId);
 
     private boolean canReadStorage(Context context) {
         return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(context,
diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
index c0eda4629..d2ef94e03 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
@@ -9,6 +9,7 @@ import android.provider.MediaStore;
 import android.support.annotation.WorkerThread;
 import android.text.TextUtils;
 
+import org.videolan.medialibrary.Medialibrary;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.R;
@@ -74,7 +75,7 @@ public class ThumbnailsProvider {
                         saveOnDisk(bitmap, thumbPath);
                     }
                 });
-        }
+        } else if (media.getId() != 0L) Medialibrary.getInstance().requestThumbnail(media.getId());
         return bitmap;
     }
 



More information about the Android mailing list