[Android] New ML set time API

Nicolas Pomepuy git at videolan.org
Fri Jan 7 11:53:56 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Nov 17 16:04:36 2021 +0100| [0b4ee743b7e3afa8a4141849889f74395eb95d60] | committer: Nicolas Pomepuy

New ML set time API

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt          | 11 ++++++-----
 medialibrary/jni/AndroidMediaLibrary.cpp                   | 14 +++++++-------
 medialibrary/jni/AndroidMediaLibrary.h                     |  4 ++--
 medialibrary/jni/medialibrary.cpp                          |  2 +-
 .../src/org/videolan/medialibrary/MedialibraryImpl.java    |  9 ++++++---
 .../org/videolan/medialibrary/interfaces/Medialibrary.java |  7 ++++++-
 .../org/videolan/medialibrary/stubs/StubMedialibrary.java  |  4 ++--
 7 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 474b02d07..e3fac3df1 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -516,12 +516,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 } else {
                     //todo verify that this info is persisted in DB
                     if (media.length <= 0 && length > 0) media.length = length
-
-                    medialibrary.setLastTime(media.id, time)
-                    //todo this is not really optimised. The ML should return the new time value right away to let us save the processed new time.
-                    // See https://code.videolan.org/videolan/medialibrary/-/issues/369
                     try {
-                        media.time = medialibrary.getMedia(media.id).time
+                        when (medialibrary.setLastTime(media.id, time)) {
+                            Medialibrary.ML_SET_TIME_ERROR -> {
+                            }
+                            Medialibrary.ML_SET_TIME_END, Medialibrary.ML_SET_TIME_BEGIN -> media.time = 0
+                            Medialibrary.ML_SET_TIME_AS_IS -> media.time = time
+                        }
                     } catch (e: NullPointerException) {
                         VLCCrashHandler.saveLog(e, "NullPointerException in PlaylistManager saveMediaMeta")
                     }
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index d9de420fa..01ad235c9 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -183,22 +183,22 @@ AndroidMediaLibrary::forceRescan()
     p_ml->forceRescan();
 }
 
-bool
+jint
 AndroidMediaLibrary::setLastPosition(int64_t mediaId, float lastPosition)
 {
     auto media = p_ml->media(mediaId);
     if (media != nullptr)
-        return media->setLastPosition( lastPosition );
-    return false;
+        return (int) media->setLastPosition( lastPosition );
+    return -1;
 }
 
-bool
+jint
 AndroidMediaLibrary::setLastTime(int64_t mediaId, int64_t time)
 {
     auto media = p_ml->media(mediaId);
     if (media != nullptr)
-        return media->setLastTime( time );
-    return false;
+        return (int) media->setLastTime( time );
+    return -1;
 }
 
 bool
@@ -441,7 +441,7 @@ AndroidMediaLibrary::genre(int64_t genreId)
 medialibrary::Query<medialibrary::IPlaylist>
 AndroidMediaLibrary::playlists(const medialibrary::QueryParameters* params)
 {
-    return p_ml->playlists(params);
+    return p_ml->playlists(medialibrary::PlaylistType::All, params);
 }
 
 medialibrary::PlaylistPtr
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 7be9b3b79..acf143271 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -52,8 +52,8 @@ public:
     void reload( const std::string& entryPoint );
     void forceParserRetry();
     void forceRescan();
-    bool setLastPosition(int64_t mediaId, float progress);
-    bool setLastTime(int64_t mediaId, int64_t progress);
+    jint setLastPosition(int64_t mediaId, float progress);
+    jint setLastTime(int64_t mediaId, int64_t progress);
     bool removeMediaFromHistory(int64_t mediaId);
     void setLibvlcInstance(libvlc_instance_t* inst);
     /* History */
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 2dc97af8f..061ec8f6c 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2074,7 +2074,7 @@ static JNINativeMethod methods[] = {
     {"nativeReload", "(Ljava/lang/String;)V", (void*)reloadEntryPoint },
     {"nativeForceParserRetry", "()V", (void*)forceParserRetry },
     {"nativeForceRescan", "()V", (void*)forceRescan },
-    {"nativeSetLastTime", "(JJ)Z", (void*)setLastTime },
+    {"nativeSetLastTime", "(JJ)I", (void*)setLastTime },
     {"nativeSetLastPosition", "(JF)Z", (void*)setLastPosition },
     {"nativeSetMediaUpdatedCbFlag", "(I)V", (void*)setMediaUpdatedCbFlag },
     {"nativeSetMediaAddedCbFlag", "(I)V", (void*)setMediaAddedCbFlag },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index 0efc535dd..a679844c6 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -483,8 +483,11 @@ public class MedialibraryImpl extends Medialibrary {
         return mIsInitiated ? nativeGetFoldersCount(type) : 0;
     }
 
-    public boolean setLastTime(long mediaId, long lastTime) {
-        return mIsInitiated && mediaId > 0 && nativeSetLastTime(mediaId, lastTime);
+    public int setLastTime(long mediaId, long lastTime) {
+        if (!mIsInitiated || mediaId < 1) {
+            return ML_SET_TIME_ERROR;
+        }
+        return nativeSetLastTime(mediaId, lastTime);
     }
 
     public boolean setLastPosition(long mediaId, float position) {
@@ -665,7 +668,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native void nativeReload(String entryPoint);
     private native void nativeForceParserRetry();
     private native void nativeForceRescan();
-    private native boolean nativeSetLastTime(long mediaId, long progress);
+    private native int nativeSetLastTime(long mediaId, long progress);
     private native boolean nativeSetLastPosition(long mediaId, float position);
     private native void nativeSetMediaUpdatedCbFlag(int flags);
     private native void nativeSetMediaAddedCbFlag(int flags);
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index 52b39edf6..1abf4c072 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -88,6 +88,11 @@ abstract public class Medialibrary {
     public static final int ML_INIT_DB_CORRUPTED = 4;
     public static final int ML_INIT_DB_UNRECOVERABLE = 5;
 
+    public static final int ML_SET_TIME_ERROR = 0;
+    public static final int ML_SET_TIME_BEGIN = 1;
+    public static final int ML_SET_TIME_AS_IS = 2;
+    public static final int ML_SET_TIME_END = 3;
+
     public static final MediaWrapper[] EMPTY_COLLECTION = {};
     public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
     public static final String THUMBS_FOLDER_NAME = "/thumbs";
@@ -772,7 +777,7 @@ abstract public class Medialibrary {
     abstract public MediaWrapper addStream(String mrl, String title);
     abstract public Folder[] getFolders(int type, int sort, boolean desc, boolean includeMissing, int nbItems, int offset);
     abstract public int getFoldersCount(int type);
-    abstract public boolean setLastTime(long mediaId, long time);
+    abstract public int setLastTime(long mediaId, long time);
     abstract public boolean setLastPosition(long mediaId, float position);
     abstract public SearchAggregate search(String query, boolean includeMissing);
     abstract public MediaWrapper[] searchMedia(String query);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index d5497a2e2..070ffa8ce 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -496,7 +496,7 @@ public class StubMedialibrary extends Medialibrary {
 
     public void requestThumbnail(long id) {}
 
-    public boolean setLastTime(long mediaId, long time) {
+    public int setLastTime(long mediaId, long time) {
         for (int i = 0; i < dt.mVideoMediaWrappers.size(); i++) {
             MediaWrapper media = dt.mVideoMediaWrappers.get(i);
             if (media.getId() == mediaId) {
@@ -504,7 +504,7 @@ public class StubMedialibrary extends Medialibrary {
                 dt.mVideoMediaWrappers.set(i, media);
             }
         }
-        return true;
+        return ML_SET_TIME_BEGIN;
     }
 
     public boolean setLastPosition(long mediaId, float poistion) {



More information about the Android mailing list