[Android] History JNI call implem start

Geoffrey Métais git at videolan.org
Wed Nov 23 18:53:24 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Nov 23 18:52:47 2016 +0100| [87d0b09316778e891c7d79a2c9a2befb8728762b] | committer: Geoffrey Métais

History JNI call implem start

lastStreamsPlayed still TODO

> https://code.videolan.org/videolan/vlc-android/commit/87d0b09316778e891c7d79a2c9a2befb8728762b
---

 medialibrary/jni/AndroidMediaLibrary.cpp           | 18 ++++++++++++++++
 medialibrary/jni/AndroidMediaLibrary.h             |  6 ++++++
 medialibrary/jni/medialibrary.cpp                  | 25 ++++++++++++++++++++++
 .../org/videolan/medialibrary/Medialibrary.java    | 15 ++++++++++---
 .../src/org/videolan/vlc/gui/HistoryFragment.java  |  1 +
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index e557b97..3c294c4 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -174,6 +174,24 @@ AndroidMediaLibrary::lastMediaPlayed()
     return p_ml->lastMediaPlayed();
 }
 
+bool
+AndroidMediaLibrary::addToHistory( const std::string& mrl )
+{
+    p_ml->addToHistory(mrl);
+}
+
+std::vector<medialibrary::HistoryPtr>
+AndroidMediaLibrary::lastStreamsPlayed()
+{
+    return p_ml->lastStreamsPlayed();
+}
+
+bool
+AndroidMediaLibrary::clearHistory()
+{
+    return p_ml->clearHistory();
+}
+
 medialibrary::SearchAggregate
 AndroidMediaLibrary::search(const std::string& query)
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 2c7f5e6..df093b4 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -15,6 +15,7 @@
 #include <medialibrary/IAlbum.h>
 #include <medialibrary/IArtist.h>
 #include <medialibrary/IGenre.h>
+#include <medialibrary/IHistoryEntry.h>
 #include <medialibrary/IPlaylist.h>
 #include <medialibrary/IFolder.h>
 #include <medialibrary/Types.h>
@@ -45,7 +46,12 @@ public:
     void reload( const std::string& entryPoint );
     bool increasePlayCount(int64_t mediaId);
     bool updateProgress(int64_t mediaId, int64_t time);
+    /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
+    bool addToHistory( const std::string& mrl );
+    std::vector<medialibrary::HistoryPtr> lastStreamsPlayed();
+    bool clearHistory();
+
     medialibrary::SearchAggregate search(const std::string& query);
     medialibrary::MediaPtr media(long id);
     medialibrary::MediaPtr media(const std::string& mrl);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 60b9334..9b4cd9d 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -199,6 +199,28 @@ lastMediaPLayed(JNIEnv* env, jobject thiz)
     return mediaRefs;
 }
 
+jboolean
+addToHistory(JNIEnv* env, jobject thiz, jstring mrl)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    const char *mrl_cstr = env->GetStringUTFChars(mrl, JNI_FALSE);
+    jboolean ok = aml->addToHistory(mrl_cstr);
+    env->ReleaseStringUTFChars(mrl, mrl_cstr);
+    return ok;
+}
+
+jobjectArray
+lastStreamsPlayed(JNIEnv* env, jobject thiz)
+{
+    //TODO
+    return nullptr;
+}
+
+bool clearHistory(JNIEnv* env, jobject thiz)
+{
+    return MediaLibrary_getInstance(env, thiz)->clearHistory();
+}
+
 jobjectArray
 getVideos(JNIEnv* env, jobject thiz)
 {
@@ -558,6 +580,9 @@ static JNINativeMethod methods[] = {
     {"nativeRemoveDevice", "(Ljava/lang/String;)Z", (void*)removeDevice },
     {"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
     {"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
+    {"nativeLastStreamsPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastStreamsPlayed },
+    {"nativeAddToHistory", "(Ljava/lang/String;)Z", (void*)addToHistory },
+    {"nativeClearHistory", "()Z", (void*)clearHistory },
     {"nativeGetVideos", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getVideos },
     {"nativeGetAudio", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)getAudio },
     {"nativeSearch", "(Ljava/lang/String;)Lorg/videolan/medialibrary/media/SearchAggregate;", (void*)search},
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index eba54d7..74c2575 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -202,6 +202,14 @@ public class Medialibrary {
         return mIsInitiated ? nativeLastMediaPlayed() : EMPTY_COLLECTION;
     }
 
+    public boolean clearHistory() {
+        return mIsInitiated && nativeClearHistory();
+    }
+
+    public boolean addToHistory(String mrl) {
+        return mIsInitiated && nativeAddToHistory(mrl);
+    }
+
     public MediaWrapper getMedia(long id) {
         return nativeGetMedia(id);
     }
@@ -218,9 +226,7 @@ public class Medialibrary {
     }
 
     public boolean increasePlayCount(long mediaId) {
-        if (!mIsInitiated)
-            return false;
-        return mediaId > 0 && nativeIncreasePlayCount(mediaId);
+        return mIsInitiated && mediaId > 0 && nativeIncreasePlayCount(mediaId);
     }
 
     public boolean updateProgress(MediaWrapper mw, long time) {
@@ -397,6 +403,9 @@ public class Medialibrary {
     private native String[] nativeEntryPoints();
     private native boolean nativeRemoveDevice(String uuid);
     private native MediaWrapper[] nativeLastMediaPlayed();
+    private native MediaWrapper[] nativeLastStreamsPlayed();
+    private native  boolean nativeAddToHistory(String mrl);
+    private native  boolean nativeClearHistory();
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
     private native MediaWrapper[] nativeGetVideos();
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 9e0f1c1..865f6f4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -147,6 +147,7 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
 
     @Override
     public void clearHistory() {
+        mMediaLibrary.clearHistory();
         mHistoryAdapter.clear();
         updateEmptyView();
     }



More information about the Android mailing list