[Android] Split media list search result in C++ code
Geoffrey Métais
git at videolan.org
Wed Aug 8 15:46:38 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 8 15:03:51 2018 +0200| [25e446655fc10410fb6d7253c72d8a2eb271c39f] | committer: Geoffrey Métais
Split media list search result in C++ code
> https://code.videolan.org/videolan/vlc-android/commit/25e446655fc10410fb6d7253c72d8a2eb271c39f
---
medialibrary/jni/medialibrary.cpp | 2 +-
medialibrary/jni/utils.cpp | 22 ++++++++++++++++++----
.../medialibrary/media/SearchAggregate.java | 17 +++--------------
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 20a29ca30..d3b8266cd 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1081,7 +1081,7 @@ int MediaLibraryJNI_OnLoad(JavaVM *vm, JNIEnv* env)
GET_ID(GetMethodID,
ml_fields.SearchAggregate.initID,
ml_fields.SearchAggregate.clazz,
- "<init>", "([Lorg/videolan/medialibrary/media/Album;[Lorg/videolan/medialibrary/media/Artist;[Lorg/videolan/medialibrary/media/Genre;[Lorg/videolan/medialibrary/media/MediaWrapper;[Lorg/videolan/medialibrary/media/Playlist;)V");
+ "<init>", "([Lorg/videolan/medialibrary/media/Album;[Lorg/videolan/medialibrary/media/Artist;[Lorg/videolan/medialibrary/media/Genre;[Lorg/videolan/medialibrary/media/MediaWrapper;[Lorg/videolan/medialibrary/media/MediaWrapper;[Lorg/videolan/medialibrary/media/Playlist;)V");
GET_ID(GetFieldID,
ml_fields.MediaLibrary.instanceID,
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index e6b03ac2a..7b6188fdc 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -184,15 +184,29 @@ convertSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::SearchAg
env->DeleteLocalRef(item);
}
//Media
- jobjectArray mediaList = (jobjectArray) env->NewObjectArray(searchAggregatePtr.media->count(), fields->MediaWrapper.clazz, NULL);
- index = -1;
+ std::vector<medialibrary::MediaPtr> videos = {};
+ std::vector<medialibrary::MediaPtr> tracks = {};
for(medialibrary::MediaPtr const& media : searchAggregatePtr.media->all()) {
+ if (media->subType() == medialibrary::IMedia::SubType::AlbumTrack) tracks.push_back(media);
+ else videos.push_back(media);
+ }
+ jobjectArray videoList = (jobjectArray) env->NewObjectArray(videos.size(), fields->MediaWrapper.clazz, NULL);
+ index = -1;
+ for(medialibrary::MediaPtr const& media : videos) {
+ jobject item = mediaToMediaWrapper(env, fields, media);
+ env->SetObjectArrayElement(videoList, ++index, item);
+ env->DeleteLocalRef(item);
+ }
+ jobjectArray tracksList = (jobjectArray) env->NewObjectArray(tracks.size(), fields->MediaWrapper.clazz, NULL);
+ index = -1;
+ for(medialibrary::MediaPtr const& media : tracks) {
jobject item = mediaToMediaWrapper(env, fields, media);
- env->SetObjectArrayElement(mediaList, ++index, item);
+ env->SetObjectArrayElement(tracksList, ++index, item);
env->DeleteLocalRef(item);
}
+
return env->NewObject(fields->SearchAggregate.clazz, fields->SearchAggregate.initID,
- albums, artists, genres, mediaList, playlists);
+ albums, artists, genres, videoList, tracksList, playlists);
}
jobjectArray
diff --git a/medialibrary/src/org/videolan/medialibrary/media/SearchAggregate.java b/medialibrary/src/org/videolan/medialibrary/media/SearchAggregate.java
index 749392522..4151c04da 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/SearchAggregate.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/SearchAggregate.java
@@ -2,9 +2,6 @@ package org.videolan.medialibrary.media;
import org.videolan.medialibrary.Tools;
-import java.util.LinkedList;
-import java.util.List;
-
public class SearchAggregate {
private static final String TAG = "VLC/SearchAggregate";
@@ -23,20 +20,12 @@ public class SearchAggregate {
this.tracks = null;
this.playlists = null;}
- public SearchAggregate(Album[] albums, Artist[] artists, Genre[] genres, MediaWrapper[] media, Playlist[] playlists) {
+ public SearchAggregate(Album[] albums, Artist[] artists, Genre[] genres, MediaWrapper[] videos, MediaWrapper[] tracks, Playlist[] playlists) {
this.albums = albums;
this.artists = artists;
this.genres = genres;
- final List<MediaWrapper> vidz = new LinkedList<>();
- final List<MediaWrapper> trackz = new LinkedList<>();
- for (MediaWrapper mw : media) {
- if (mw.getType() == MediaWrapper.TYPE_VIDEO) vidz.add(mw);
- else trackz.add(mw);
- }
- videos = new MediaWrapper[vidz.size()];
- vidz.toArray(videos);
- tracks = new MediaWrapper[trackz.size()];
- trackz.toArray(tracks);
+ this.videos = videos;
+ this.tracks = tracks;
this.playlists = playlists;
}
More information about the Android
mailing list