[Android] medialib: Update to recent API changes

Hugo Beauzée-Luyssen git at videolan.org
Fri Jun 29 16:04:29 CEST 2018


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Jun 29 14:24:09 2018 +0200| [200f08932c44b1e091545943238c6a576495ff80] | committer: Hugo Beauzée-Luyssen

medialib: Update to recent API changes

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

 medialibrary/jni/AndroidMediaLibrary.cpp |  6 +--
 medialibrary/jni/AndroidMediaLibrary.h   |  2 +-
 medialibrary/jni/medialibrary.cpp        | 13 +++++--
 medialibrary/jni/utils.cpp               | 63 +++++---------------------------
 medialibrary/jni/utils.h                 |  1 -
 5 files changed, 23 insertions(+), 62 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index d8073a62c..63e26c38e 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -207,10 +207,10 @@ AndroidMediaLibrary::search(const std::string& query)
     return p_ml->search(query);
 }
 
-medialibrary::MediaSearchAggregate
+std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::searchMedia(const std::string& query)
 {
-    return p_ml->searchMedia(query);
+    return p_ml->searchMedia(query)->all();
 }
 
 std::vector<medialibrary::PlaylistPtr>
@@ -333,7 +333,7 @@ std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::mediaFromArtist( int64_t artistId, const medialibrary::QueryParameters* params )
 {
     auto artist = p_ml->artist(artistId);
-    return artist == nullptr ? std::vector<medialibrary::MediaPtr>() : artist->media(params)->all();
+    return artist == nullptr ? std::vector<medialibrary::MediaPtr>() : artist->tracks(params)->all();
 }
 
 std::vector<medialibrary::AlbumPtr>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 79112ee34..c9f41dd7c 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -55,7 +55,7 @@ public:
     bool clearHistory();
 
     medialibrary::SearchAggregate search(const std::string& query);
-    medialibrary::MediaSearchAggregate searchMedia(const std::string& query);
+    std::vector<medialibrary::MediaPtr> searchMedia(const std::string& query);
     std::vector<medialibrary::PlaylistPtr> searchPlaylists(const std::string& query);
     std::vector<medialibrary::AlbumPtr> searchAlbums(const std::string& query);
     std::vector<medialibrary::GenrePtr> searchGenre(const std::string& query);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 0f77a264f..c7a3626a8 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -349,14 +349,21 @@ search(JNIEnv* env, jobject thiz, jstring query)
     return searchResult;
 }
 
-jobject
+jobjectArray
 searchMedia(JNIEnv* env, jobject thiz, jstring query)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     const char *queryChar = env->GetStringUTFChars(query, JNI_FALSE);
-    jobject searchResult = convertMediaSearchAggregateObject(env, &ml_fields, aml->searchMedia(queryChar));
+    auto searchResult = aml->searchMedia(queryChar);
+    jobjectArray mediaList = (jobjectArray) env->NewObjectArray(searchResult.size(), ml_fields.MediaWrapper.clazz, NULL);
+    int index = -1;
+    for(medialibrary::MediaPtr const& media : searchResult) {
+        jobject item = mediaToMediaWrapper(env, &ml_fields, media);
+        env->SetObjectArrayElement(mediaList, ++index, item);
+        env->DeleteLocalRef(item);
+    }
     env->ReleaseStringUTFChars(query, queryChar);
-    return searchResult;
+    return mediaList;
 }
 
 jobjectArray
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 27e13f607..3f353acd1 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -149,59 +149,6 @@ convertPlaylistObject(JNIEnv* env, fields *fields, medialibrary::PlaylistPtr con
     return item;
 }
 
-jobject
-convertMediaSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::MediaSearchAggregate const& mediaSearchAggregatePtr)
-{
-    jobjectArray episodes = (jobjectArray) env->NewObjectArray(mediaSearchAggregatePtr.episodes->count(), fields->MediaWrapper.clazz, NULL);
-    int index = -1, epDrops = 0;
-    for(medialibrary::MediaPtr const& media : mediaSearchAggregatePtr.episodes->all()) {
-        jobject item = mediaToMediaWrapper(env, fields, media);
-        if (item != nullptr)
-            env->SetObjectArrayElement(episodes, ++index, item);
-        else
-            ++epDrops;
-        env->DeleteLocalRef(item);
-    }
-    jobjectArray movies = (jobjectArray) env->NewObjectArray(mediaSearchAggregatePtr.movies->count(), fields->MediaWrapper.clazz, NULL);
-    index = -1;
-    int movieDrops = 0;
-    for(medialibrary::MediaPtr const& media : mediaSearchAggregatePtr.movies->all()) {
-        jobject item = mediaToMediaWrapper(env, fields, media);
-        if (item != nullptr)
-            env->SetObjectArrayElement(movies, ++index, item);
-        else
-            ++movieDrops;
-        env->DeleteLocalRef(item);
-    }
-    jobjectArray others = (jobjectArray) env->NewObjectArray(mediaSearchAggregatePtr.others->count(), fields->MediaWrapper.clazz, NULL);
-    index = -1;
-    int othersDrops = 0;
-    for(medialibrary::MediaPtr const& media : mediaSearchAggregatePtr.others->all()) {
-        jobject item = mediaToMediaWrapper(env, fields, media);
-        if (item != nullptr)
-            env->SetObjectArrayElement(others, ++index, item);
-        else
-            ++othersDrops;
-        env->DeleteLocalRef(item);
-    }
-    jobjectArray tracks = (jobjectArray) env->NewObjectArray(mediaSearchAggregatePtr.tracks->count(), fields->MediaWrapper.clazz, NULL);
-    index = -1;
-    int tracksDrops = 0;
-    for(medialibrary::MediaPtr const& media : mediaSearchAggregatePtr.tracks->all()) {
-        jobject item = mediaToMediaWrapper(env, fields, media);
-        if (item != nullptr)
-            env->SetObjectArrayElement(tracks, ++index, item);
-        else
-            ++tracksDrops;
-        env->DeleteLocalRef(item);
-    }
-    return env->NewObject(fields->MediaSearchAggregate.clazz, fields->MediaSearchAggregate.initID,
-                          filteredArray(env, episodes, fields->MediaWrapper.clazz, epDrops),
-                          filteredArray(env, movies, fields->MediaWrapper.clazz, movieDrops),
-                          filteredArray(env, others, fields->MediaWrapper.clazz, othersDrops),
-                          filteredArray(env, tracks, fields->MediaWrapper.clazz, tracksDrops));
-}
-
 jobject
 convertSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::SearchAggregate const& searchAggregatePtr)
 {
@@ -237,8 +184,16 @@ convertSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::SearchAg
         env->SetObjectArrayElement(playlists, ++index, item);
         env->DeleteLocalRef(item);
     }
+    //Media
+    jobjectArray mediaList = (jobjectArray) env->NewObjectArray(searchAggregatePtr.media->count(), fields->MediaWrapper.clazz, NULL);
+    index = -1;
+    for(medialibrary::MediaPtr const& media : searchAggregatePtr.media->all()) {
+        jobject item = mediaToMediaWrapper(env, fields, media);
+        env->SetObjectArrayElement(mediaList, ++index, item);
+        env->DeleteLocalRef(item);
+    }
     return env->NewObject(fields->SearchAggregate.clazz, fields->SearchAggregate.initID,
-                          albums, artists, genres, convertMediaSearchAggregateObject(env, fields, searchAggregatePtr.media), playlists);
+                          albums, artists, genres, mediaList, playlists);
 }
 
 jobject
diff --git a/medialibrary/jni/utils.h b/medialibrary/jni/utils.h
index ebe60f7d1..cf7d58dff 100644
--- a/medialibrary/jni/utils.h
+++ b/medialibrary/jni/utils.h
@@ -98,7 +98,6 @@ jobject convertArtistObject(JNIEnv* env, fields *fields, medialibrary::ArtistPtr
 jobject convertGenreObject(JNIEnv* env, fields *fields, medialibrary::GenrePtr const& genrePtr);
 jobject convertPlaylistObject(JNIEnv* env, fields *fields, medialibrary::PlaylistPtr const& genrePtr);
 jobject convertSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::SearchAggregate const& searchAggregatePtr);
-jobject convertMediaSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::MediaSearchAggregate const& searchAggregatePtr);
 jobject convertHistoryItemObject(JNIEnv* env, fields *fields, medialibrary::HistoryPtr const& historyPtr);
 jobjectArray filteredArray(JNIEnv* env, jobjectArray array, jclass clazz, int removalCount = -1);
 



More information about the Android mailing list