[Android] Implement duration when adding external media

Nicolas Pomepuy git at videolan.org
Tue Nov 24 09:39:49 CET 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Nov 17 10:13:55 2020 +0100| [174bc63e7e2bf5cd0ef9b5e36402f7aa97387669] | committer: Hugo Beauzée-Luyssen

Implement duration when adding external media

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

 .../src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt            | 2 +-
 .../src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt          | 2 +-
 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt       | 3 ++-
 medialibrary/jni/AndroidMediaLibrary.cpp                            | 4 ++--
 medialibrary/jni/AndroidMediaLibrary.h                              | 2 +-
 medialibrary/jni/medialibrary.cpp                                   | 6 +++---
 medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java    | 6 +++---
 .../src/org/videolan/medialibrary/interfaces/Medialibrary.java      | 2 +-
 .../src/org/videolan/medialibrary/stubs/StubMedialibrary.java       | 2 +-
 9 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
index 2fa35e1a7..94fbde97c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
@@ -139,7 +139,7 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
                     if (media != null)
                         ids.add(media.id)
                     else {
-                        media = medialibrary.addMedia(mw.location)
+                        media = medialibrary.addMedia(mw.location, -1L)
                         if (media != null) ids.add(media.id)
                     }
                 } else
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
index 1ddf18111..ae4ad4c01 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
@@ -175,7 +175,7 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
                     if (media != null)
                         ids.add(media.id)
                     else {
-                        media = medialibrary.addMedia(mw.location)
+                        media = medialibrary.addMedia(mw.location, -1L)
                         if (media != null) ids.add(media.id)
                     }
                 } else
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 be3bc2cc7..b19b0dc77 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -810,6 +810,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     } ?: return
                     if (newMedia) {
                         loadMediaMeta(mw)
+                        mw.length = player.getLength()
                         saveMediaList()
                         savePosition(reset = true)
                         saveCurrentMedia()
@@ -867,7 +868,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         medialibrary.addStream(entryUrl ?: mw.uri.toString(), mw.title).also {
                             entryUrl = null
                         }
-                    } else medialibrary.addMedia(mw.uri.toString())
+                    } else medialibrary.addMedia(mw.uri.toString(), mw.length)
                     if (internalMedia != null) id = internalMedia.id
                 }
             }
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 825e0de62..8efd5b6ce 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -341,9 +341,9 @@ AndroidMediaLibrary::media(const std::string& mrl)
 }
 
 medialibrary::MediaPtr
-AndroidMediaLibrary::addMedia(const std::string& mrl)
+AndroidMediaLibrary::addMedia(const std::string& mrl, long duration)
 {
-    return p_ml->addExternalMedia(mrl);
+    return p_ml->addExternalMedia(mrl, duration);
 }
 
 bool
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index ca9065252..c033234e9 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -79,7 +79,7 @@ public:
     medialibrary::Query<medialibrary::IMediaGroup> searchVideoGroups( const std::string& query, const medialibrary::QueryParameters* params = nullptr );
         medialibrary::MediaPtr media(long id);
     medialibrary::MediaPtr media(const std::string& mrl);
-    medialibrary::MediaPtr addMedia(const std::string& mrl);
+    medialibrary::MediaPtr addMedia(const std::string& mrl, long duration);
     bool removeExternalMedia(long id);
     medialibrary::MediaPtr addStream(const std::string& mrl, const std::string& title);
     medialibrary::Query<medialibrary::IMedia> videoFiles( const medialibrary::QueryParameters* params = nullptr );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 2e6685837..6ab4e8ff3 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -739,10 +739,10 @@ getMediaFromMrl(JNIEnv* env, jobject thiz, jstring mrl) {
 }
 
 jobject
-addMedia(JNIEnv* env, jobject thiz, jstring mrl) {
+addMedia(JNIEnv* env, jobject thiz, jstring mrl, jlong duration) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     const char *char_mrl = env->GetStringUTFChars(mrl, JNI_FALSE);
-    jobject mw = mediaToMediaWrapper(env, &ml_fields, aml->addMedia(char_mrl));
+    jobject mw = mediaToMediaWrapper(env, &ml_fields, aml->addMedia(char_mrl, duration));
     env->ReleaseStringUTFChars(mrl, char_mrl);
     return mw;
 }
@@ -2088,7 +2088,7 @@ static JNINativeMethod methods[] = {
     {"nativeGetPlaylistSearchCount", "(Ljava/lang/String;)I", (void*)getPlaylistSearchCount },
     {"nativeGetMedia", "(J)Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getMedia },
     {"nativeGetMediaFromMrl", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getMediaFromMrl },
-    {"nativeAddMedia", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)addMedia },
+    {"nativeAddMedia", "(Ljava/lang/String;J)Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)addMedia },
     {"nativeRemoveExternalMedia", "(J)Z", (void*)removeExternalMedia },
     {"nativeAddStream", "(Ljava/lang/String;Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)addStream },
     {"nativeGetVideoCount", "()I", (void*)getVideoCount },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index 0ea70f0db..cbd3626ea 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -439,9 +439,9 @@ public class MedialibraryImpl extends Medialibrary {
     }
 
     @Nullable
-    public MediaWrapper addMedia(String mrl) {
+    public MediaWrapper addMedia(String mrl, long duration) {
         final String vlcMrl = Tools.encodeVLCMrl(mrl);
-        return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl) : null;
+        return mIsInitiated && !TextUtils.isEmpty(vlcMrl) ? nativeAddMedia(vlcMrl, duration) : null;
     }
 
     public boolean removeExternalMedia(long id) {
@@ -592,7 +592,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native  boolean nativeClearHistory();
     private native MediaWrapper nativeGetMedia(long id);
     private native MediaWrapper nativeGetMediaFromMrl(String mrl);
-    private native MediaWrapper nativeAddMedia(String mrl);
+    private native MediaWrapper nativeAddMedia(String mrl, long duration);
     private native boolean nativeRemoveExternalMedia(long id);
     private native MediaWrapper nativeAddStream(String mrl, String title);
     private native MediaWrapper[] nativeGetVideos();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index 6e24ebcbc..eec0bb3e2 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -742,7 +742,7 @@ abstract public class Medialibrary {
     abstract public MediaWrapper getMedia(long id);
     abstract public MediaWrapper getMedia(Uri uri);
     abstract public MediaWrapper getMedia(String mrl);
-    abstract public MediaWrapper addMedia(String mrl);
+    abstract public MediaWrapper addMedia(String mrl, long duration);
     abstract public boolean removeExternalMedia(long id);
     abstract public MediaWrapper addStream(String mrl, String title);
     abstract public Folder[] getFolders(int type, int sort, boolean desc, int nbItems, int offset);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index ad1b1d805..93ed7c346 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -443,7 +443,7 @@ public class StubMedialibrary extends Medialibrary {
 
     /* TODO maybe add a list of medias not in the medialibrary which can be retrieved with mrl to
      * simulate adding a media from system */
-    public MediaWrapper addMedia(String mrl) {
+    public MediaWrapper addMedia(String mrl, long duration) {
         return null;
     }
 



More information about the Android mailing list