[Android] Update to Medialibrary API

Geoffrey Métais git at videolan.org
Tue Nov 29 12:04:43 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 25 16:13:25 2016 +0100| [bf663f4aad4052b424ce55e63c5542319b508431] | committer: Geoffrey Métais

Update to Medialibrary API

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

 medialibrary/jni/AndroidMediaLibrary.cpp                |  4 ++--
 medialibrary/jni/AndroidMediaLibrary.h                  |  2 +-
 medialibrary/jni/medialibrary.cpp                       | 10 ++++++----
 medialibrary/jni/utils.cpp                              |  3 ++-
 .../src/org/videolan/medialibrary/Medialibrary.java     |  6 +++---
 .../org/videolan/medialibrary/media/HistoryItem.java    | 17 ++++++++++++-----
 .../org/videolan/medialibrary/media/MediaWrapper.java   |  4 ++++
 7 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 03206ea..1c06419 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -175,9 +175,9 @@ AndroidMediaLibrary::lastMediaPlayed()
 }
 
 bool
-AndroidMediaLibrary::addToHistory( const std::string& mrl )
+AndroidMediaLibrary::addToHistory( const std::string& mrl, const std::string& title )
 {
-    return p_ml->addToHistory(mrl);
+    return p_ml->addToHistory(mrl, title);
 }
 
 std::vector<medialibrary::HistoryPtr>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index df093b4..77429a5 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -48,7 +48,7 @@ public:
     bool updateProgress(int64_t mediaId, int64_t time);
     /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
-    bool addToHistory( const std::string& mrl );
+    bool addToHistory( const std::string& mrl, const std::string& title );
     std::vector<medialibrary::HistoryPtr> lastStreamsPlayed();
     bool clearHistory();
 
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 811884a..74d18cf 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -200,12 +200,14 @@ lastMediaPLayed(JNIEnv* env, jobject thiz)
 }
 
 jboolean
-addToHistory(JNIEnv* env, jobject thiz, jstring mrl)
+addToHistory(JNIEnv* env, jobject thiz, jstring mrl, jstring title)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     const char *mrl_cstr = env->GetStringUTFChars(mrl, JNI_FALSE);
-    jboolean ok = aml->addToHistory(mrl_cstr);
+    const char *title_cstr = env->GetStringUTFChars(title, JNI_FALSE);
+    jboolean ok = aml->addToHistory(mrl_cstr, title_cstr);
     env->ReleaseStringUTFChars(mrl, mrl_cstr);
+    env->ReleaseStringUTFChars(title, title_cstr);
     return ok;
 }
 
@@ -589,7 +591,7 @@ static JNINativeMethod methods[] = {
     {"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
     {"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
     {"nativeLastStreamsPlayed", "()[Lorg/videolan/medialibrary/media/HistoryItem;", (void*)lastStreamsPlayed },
-    {"nativeAddToHistory", "(Ljava/lang/String;)Z", (void*)addToHistory },
+    {"nativeAddToHistory", "(Ljava/lang/String;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 },
@@ -758,7 +760,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
     GET_ID(GetMethodID,
            ml_fields.HistoryItem.initID,
            ml_fields.HistoryItem.clazz,
-           "<init>", "(Ljava/lang/String;JZ)V");
+           "<init>", "(Ljava/lang/String;Ljava/lang/String;JZ)V");
 ///
     GET_CLASS(ml_fields.MediaSearchAggregate.clazz, "org/videolan/medialibrary/media/MediaSearchAggregate", true);
 
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 4302589..097684b 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -205,7 +205,8 @@ jobject
 convertHistoryItemObject(JNIEnv* env, fields *fields, medialibrary::HistoryPtr const& historyPtr)
 {
     jstring mrl = env->NewStringUTF(historyPtr->mrl().c_str());
-    jobject item = env->NewObject(fields->HistoryItem.clazz, fields->HistoryItem.initID, mrl,
+    jstring title = env->NewStringUTF(historyPtr->title().c_str());
+    jobject item = env->NewObject(fields->HistoryItem.clazz, fields->HistoryItem.initID, mrl, title,
                           (jlong) historyPtr->insertionDate(), (jboolean) historyPtr->isFavorite());
     env->DeleteLocalRef(mrl);
     return item;
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 8992a56..82a1f7a 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -211,8 +211,8 @@ public class Medialibrary {
         return mIsInitiated && nativeClearHistory();
     }
 
-    public boolean addToHistory(String mrl) {
-        return mIsInitiated && nativeAddToHistory(mrl);
+    public boolean addToHistory(String mrl, String title) {
+        return mIsInitiated && nativeAddToHistory(mrl, title);
     }
 
     public MediaWrapper getMedia(long id) {
@@ -409,7 +409,7 @@ public class Medialibrary {
     private native boolean nativeRemoveDevice(String uuid);
     private native MediaWrapper[] nativeLastMediaPlayed();
     private native HistoryItem[] nativeLastStreamsPlayed();
-    private native  boolean nativeAddToHistory(String mrl);
+    private native  boolean nativeAddToHistory(String mrl, String title);
     private native  boolean nativeClearHistory();
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
diff --git a/medialibrary/src/org/videolan/medialibrary/media/HistoryItem.java b/medialibrary/src/org/videolan/medialibrary/media/HistoryItem.java
index b25cdd3..734cf02 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/HistoryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/HistoryItem.java
@@ -11,18 +11,21 @@ import org.videolan.medialibrary.Medialibrary;
 import java.util.Date;
 
 public class HistoryItem extends MediaLibraryItem {
-    String mrl;
-    boolean favorite;
-    long insertionDate;
+    private String mrl, title;
+    private boolean favorite;
+    private long insertionDate;
 
-    public HistoryItem (String mrl, long insertionDate, boolean favorite) {
+    public HistoryItem (String mrl, String title, long insertionDate, boolean favorite) {
         this.mrl = mrl;
+        this.title = title;
         this.favorite = favorite;
         this.insertionDate = insertionDate;
     }
 
     public MediaWrapper getMedia() {
-        return new MediaWrapper(Uri.parse(mrl));
+        MediaWrapper mw = new MediaWrapper(Uri.parse(mrl));
+        mw.setTitle(title);
+        return mw;
     }
     @Override
     public MediaWrapper[] getTracks(@Nullable Medialibrary ml) {
@@ -38,6 +41,10 @@ public class HistoryItem extends MediaLibraryItem {
         return mrl;
     }
 
+    public String getTitle() {
+        return title;
+    }
+
     public boolean isFavorite() {
         return favorite;
     }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
index ed456f2..07c4455 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
@@ -406,6 +406,10 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
         mDisplayTitle = title;
     }
 
+    public void setTitle(String title){
+        mTitle = title;
+    }
+
     public void setArtist(String artist){
         mArtist = artist;
     }



More information about the Android mailing list