[Android] aml: Update to new stream history API

Hugo Beauzée-Luyssen git at videolan.org
Wed Jul 4 14:03:56 CEST 2018


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Jul  4 14:02:20 2018 +0200| [2c2553a4a3c8027a865c98214ca9302bebec51af] | committer: Hugo Beauzée-Luyssen

aml: Update to new stream history API

> https://code.videolan.org/videolan/vlc-android/commit/2c2553a4a3c8027a865c98214ca9302bebec51af
---

 medialibrary/jni/AndroidMediaLibrary.cpp | 12 ++++++------
 medialibrary/jni/AndroidMediaLibrary.h   |  2 +-
 medialibrary/jni/medialibrary.cpp        | 16 +++++++++-------
 medialibrary/jni/utils.cpp               | 14 --------------
 medialibrary/jni/utils.h                 |  1 -
 5 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 63e26c38e..464f23efe 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -172,7 +172,7 @@ AndroidMediaLibrary::increasePlayCount(int64_t mediaId)
 std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::lastMediaPlayed()
 {
-    return p_ml->lastMediaPlayed()->all();
+    return p_ml->history()->items( 100, 0 );
 }
 
 bool
@@ -181,18 +181,18 @@ AndroidMediaLibrary::addToHistory( const std::string& mrl, const std::string& ti
     auto media = p_ml->media( mrl );
     if ( media == nullptr )
     {
-        media = p_ml->addMedia( mrl );
+        media = p_ml->addStream( mrl );
         if ( media == nullptr )
             return false;
     }
     media->setTitle(title);
-    return p_ml->addToStreamHistory( media );
+    return true;
 }
 
-std::vector<medialibrary::HistoryPtr>
+std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::lastStreamsPlayed()
 {
-    return p_ml->lastStreamsPlayed()->all();
+    return p_ml->streamHistory()->items( 100, 0 );
 }
 
 bool
@@ -253,7 +253,7 @@ AndroidMediaLibrary::media(const std::string& mrl)
 medialibrary::MediaPtr
 AndroidMediaLibrary::addMedia(const std::string& mrl)
 {
-    return p_ml->addMedia(mrl);
+    return p_ml->addExternalMedia(mrl);
 }
 
 std::vector<medialibrary::MediaPtr>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index c9f41dd7c..cce459156 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -51,7 +51,7 @@ public:
     /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
     bool addToHistory( const std::string& mrl, const std::string& title );
-    std::vector<medialibrary::HistoryPtr> lastStreamsPlayed();
+    std::vector<medialibrary::MediaPtr> lastStreamsPlayed();
     bool clearHistory();
 
     medialibrary::SearchAggregate search(const std::string& query);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index c7a3626a8..f2a2cc008 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -237,15 +237,17 @@ jobjectArray
 lastStreamsPlayed(JNIEnv* env, jobject thiz)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
-    std::vector<medialibrary::HistoryPtr> streamsPlayed = aml->lastStreamsPlayed();
-    jobjectArray streamRefs = (jobjectArray) env->NewObjectArray(streamsPlayed.size(), ml_fields.HistoryItem.clazz, NULL);
-    int index = -1;
-    for(medialibrary::HistoryPtr const& historyItem : streamsPlayed) {
-        jobject item = convertHistoryItemObject(env, &ml_fields, historyItem);
-        env->SetObjectArrayElement(streamRefs, ++index, item);
+    std::vector<medialibrary::MediaPtr> streamsPlayed = aml->lastStreamsPlayed();
+    jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(streamsPlayed.size(), ml_fields.MediaWrapper.clazz, NULL);
+    int index = -1, drops = 0;
+    for(medialibrary::MediaPtr const& media : streamsPlayed) {
+        jobject item = mediaToMediaWrapper(env, &ml_fields, media);
+        env->SetObjectArrayElement(mediaRefs, ++index, item);
+        if (item == nullptr)
+            ++drops;
         env->DeleteLocalRef(item);
     }
-    return streamRefs;
+    return mediaRefs;
 }
 
 bool clearHistory(JNIEnv* env, jobject thiz)
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 3f353acd1..e6b03ac2a 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -5,7 +5,6 @@
 #include <medialibrary/IFile.h>
 #include <medialibrary/IMedia.h>
 #include <medialibrary/IArtist.h>
-#include <medialibrary/IHistoryEntry.h>
 #include <medialibrary/IGenre.h>
 #include <medialibrary/IAlbum.h>
 #include <medialibrary/IPlaylist.h>
@@ -196,19 +195,6 @@ convertSearchAggregateObject(JNIEnv* env, fields *fields, medialibrary::SearchAg
                           albums, artists, genres, mediaList, playlists);
 }
 
-jobject
-convertHistoryItemObject(JNIEnv* env, fields *fields, medialibrary::HistoryPtr const& historyPtr)
-{
-    auto media = historyPtr->media().get();
-    jstring mrl = env->NewStringUTF(media->files()[0]->mrl().c_str());
-    jstring title = env->NewStringUTF(media->title().c_str());
-    jobject item = env->NewObject(fields->HistoryItem.clazz, fields->HistoryItem.initID, mrl, title,
-                          (jlong) historyPtr->insertionDate(), (jboolean) false);
-    env->DeleteLocalRef(mrl);
-    env->DeleteLocalRef(title);
-    return item;
-}
-
 jobjectArray
 filteredArray(JNIEnv* env, jobjectArray array, jclass clazz, int removalCount)
 {
diff --git a/medialibrary/jni/utils.h b/medialibrary/jni/utils.h
index cf7d58dff..efce94aa7 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 convertHistoryItemObject(JNIEnv* env, fields *fields, medialibrary::HistoryPtr const& historyPtr);
 jobjectArray filteredArray(JNIEnv* env, jobjectArray array, jclass clazz, int removalCount = -1);
 
 #endif //VLC_MEDIALIB_UTILS_H



More information about the Android mailing list