[Android] Medialibrary: Add 'removeFromHistory' method

Geoffrey Métais git at videolan.org
Wed Jun 12 17:45:32 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jun 12 15:46:27 2019 +0200| [939bcaa21b45d5e2687654db2613b40ad14f34b5] | committer: Geoffrey Métais

Medialibrary: Add 'removeFromHistory' method

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

 medialibrary/jni/AndroidMediaLibrary.cpp                |  7 +++++++
 medialibrary/jni/AndroidMediaLibrary.h                  |  1 +
 medialibrary/jni/medialibrary.cpp                       |  7 +++++++
 .../org/videolan/medialibrary/media/MediaWrapper.java   | 17 ++++++++++-------
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 68b7e3b1e..e0aac0657 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -171,6 +171,13 @@ AndroidMediaLibrary::increasePlayCount(int64_t mediaId)
     return false;
 }
 
+void
+AndroidMediaLibrary::removeMediaFromHistory(int64_t mediaId)
+{
+    auto media = p_ml->media(mediaId);
+    if (media != nullptr) media->removeFromHistory();
+}
+
 std::vector<medialibrary::MediaPtr>
 AndroidMediaLibrary::lastMediaPlayed()
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 22e272047..25365fe21 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -48,6 +48,7 @@ public:
     void forceParserRetry();
     void forceRescan();
     bool increasePlayCount(int64_t mediaId);
+    void removeMediaFromHistory(int64_t mediaId);
     /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
     bool addToHistory( const std::string& mrl, const std::string& title );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 80ff9f9b0..4d7f96b79 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -209,6 +209,12 @@ increasePlayCount(JNIEnv* env, jobject thiz, jlong id)
     return MediaLibrary_getInstance(env, thiz)->increasePlayCount((int64_t)id);
 }
 
+void
+removeMediaFromHistory(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id)
+{
+    MediaLibrary_getInstance(env, medialibrary)->removeMediaFromHistory((int64_t)id);
+}
+
 jobjectArray
 lastMediaPLayed(JNIEnv* env, jobject thiz)
 {
@@ -1807,6 +1813,7 @@ static JNINativeMethod media_methods[] = {
     {"nativeSetMediaLongMetadata", "(Lorg/videolan/medialibrary/Medialibrary;JIJ)V", (void*)setMediaLongMetadata },
     {"nativeSetMediaThumbnail", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;)V", (void*)setMediaThumbnail },
     {"nativeSetMediaTitle", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;)V", (void*)setMediaTitle },
+    {"nativeRemoveFromHistory", "(Lorg/videolan/medialibrary/Medialibrary;J)V", (void*)removeMediaFromHistory },
 };
 
 static JNINativeMethod album_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
index e9b740739..b82061589 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
@@ -26,6 +26,8 @@ import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.TextUtils;
 
+import androidx.annotation.Nullable;
+
 import org.videolan.libvlc.Media;
 import org.videolan.libvlc.Media.Meta;
 import org.videolan.libvlc.Media.VideoTrack;
@@ -37,8 +39,6 @@ import org.videolan.medialibrary.Tools;
 
 import java.util.Locale;
 
-import androidx.annotation.Nullable;
-
 @SuppressWarnings("JniMissingFunction")
 public class MediaWrapper extends MediaLibraryItem implements Parcelable {
     public final static String TAG = "VLC/MediaWrapper";
@@ -502,6 +502,13 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
         if (mId != 0 && ml.isInitiated()) nativeSetMediaTitle(ml, mId, name);
     }
 
+    public void removeFromHistory() {
+        if (mId != 0L) {
+            final Medialibrary ml = Medialibrary.getInstance();
+            if (ml.isInitiated()) nativeRemoveFromHistory(ml, mId);
+        }
+    }
+
     public void setArtist(String artist) {
         mArtist = artist;
     }
@@ -678,16 +685,12 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
     }
 
     private native long nativeGetMediaLongMetadata(Medialibrary ml, long id, int metaDataType);
-
     private native String nativeGetMediaStringMetadata(Medialibrary ml, long id, int metaDataType);
-
     private native void nativeSetMediaStringMetadata(Medialibrary ml, long id, int metaDataType, String metadataValue);
-
     private native void nativeSetMediaLongMetadata(Medialibrary ml, long id, int metaDataType, long metadataValue);
-
     private native void nativeSetMediaThumbnail(Medialibrary ml, long id, String mrl);
-
     private native void nativeSetMediaTitle(Medialibrary ml, long id, String name);
+    private native void nativeRemoveFromHistory(Medialibrary ml, long id);
 
     @Nullable
     public Media.Slave[] getSlaves() {



More information about the Android mailing list