[Android] Implement the new playlist nbDurationUnknown API

Nicolas Pomepuy git at videolan.org
Thu Feb 24 10:58:19 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 25 15:33:13 2021 +0100| [8183757c9b65b85eba8259109f60028795223f75] | committer: Nicolas Pomepuy

Implement the new playlist nbDurationUnknown API

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

 application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt  | 5 ++++-
 medialibrary/jni/medialibrary.cpp                                 | 2 +-
 medialibrary/jni/utils.cpp                                        | 2 +-
 medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java  | 6 +++---
 .../src/org/videolan/medialibrary/interfaces/media/Playlist.java  | 8 +++++++-
 .../src/org/videolan/medialibrary/media/PlaylistImpl.java         | 4 ++--
 .../src/org/videolan/medialibrary/stubs/StubMedialibrary.java     | 2 +-
 .../src/org/videolan/medialibrary/stubs/StubPlaylist.java         | 4 ++--
 8 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index c6a8ebf04..4df1cf98b 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -13,6 +13,7 @@ import android.text.SpannableString
 import android.text.style.DynamicDrawableSpan
 import android.text.style.ImageSpan
 import android.util.DisplayMetrics
+import android.util.Log
 import android.view.View
 import android.widget.TextView
 import androidx.annotation.WorkerThread
@@ -31,6 +32,7 @@ import com.google.android.material.snackbar.Snackbar
 import kotlinx.coroutines.*
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.collect
+import org.videolan.BuildConfig
 import org.videolan.libvlc.Media
 import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.libvlc.util.AndroidUtil
@@ -175,7 +177,8 @@ fun asyncTextItem(view: TextView, item: MediaLibraryItem?) {
         return
     }
     val text = if (item is Playlist){
-        TextUtils.separatedString(view.context.getString(R.string.track_number, item.tracksCount), if (item.duration != 0L) Tools.millisToString(item.duration) else null)
+        val duration =if (item.duration != 0L) Tools.millisToString(item.duration) else null
+        TextUtils.separatedString(view.context.getString(R.string.track_number, item.tracksCount), if (item.nbDurationUnknown > 0) "$duration+" else duration)
     } else item.description
     if (text.isNullOrEmpty()) {
         view.visibility = View.GONE
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 3a4ede9bb..e2f84427c 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2287,7 +2287,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
     GET_ID(GetMethodID,
            ml_fields.Playlist.initID,
            ml_fields.Playlist.clazz,
-           "<init>", "(JLjava/lang/String;IJIII)V");
+           "<init>", "(JLjava/lang/String;IJIIII)V");
 
 
     GET_CLASS(ml_fields.MediaWrapper.clazz,
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 53d992881..9a5fa11ba 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -127,7 +127,7 @@ convertPlaylistObject(JNIEnv* env, fields *fields, medialibrary::PlaylistPtr con
            static_cast<bool>( includeMissing )
         };
     return utils::jni::object{ env, env->NewObject(fields->Playlist.clazz, fields->Playlist.initID,
-                          (jlong) playlistPtr->id(), name.get(), (jint)playlistPtr->media(&params)->count(), (jlong)playlistPtr->duration(), (jint)playlistPtr->nbVideo(), (jint)playlistPtr->nbAudio(), (jint)playlistPtr->nbUnknown())
+                          (jlong) playlistPtr->id(), name.get(), (jint)playlistPtr->media(&params)->count(), (jlong)playlistPtr->duration(), (jint)playlistPtr->nbVideo(), (jint)playlistPtr->nbAudio(), (jint)playlistPtr->nbUnknown(), (jint)playlistPtr->nbDurationUnknown())
     };
 }
 
diff --git a/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java b/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
index fa8fd3bf5..368501b6b 100644
--- a/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
+++ b/medialibrary/src/org/videolan/medialibrary/MLServiceLocator.java
@@ -220,11 +220,11 @@ public class MLServiceLocator {
     }
 
     //Playlist
-    public static Playlist getAbstractPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
+    public static Playlist getAbstractPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown, int nbDurationUnknown) {
         if (sMode == LocatorMode.VLC_ANDROID) {
-            return new PlaylistImpl(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
+            return new PlaylistImpl(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown, nbDurationUnknown);
         } else {
-            return new StubPlaylist(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
+            return new StubPlaylist(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown, nbDurationUnknown);
         }
     }
 
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
index 1a065e142..9feebd32a 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/Playlist.java
@@ -15,14 +15,16 @@ public abstract class Playlist extends MediaLibraryItem {
     protected long mNbVideo;
     protected long mNbAudio;
     protected long mNbUnknown;
+    protected long mNbDurationUnknown;
 
-    protected Playlist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
+    protected Playlist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown, int nbDurationUnknown) {
         super(id, name);
         mTracksCount = trackCount;
         mDuration = duration;
         mNbVideo = nbVideo;
         mNbAudio = nbAudio;
         mNbUnknown = nbUnknown;
+        mNbDurationUnknown = nbDurationUnknown;
     }
 
     abstract public MediaWrapper[] getTracks(boolean includeMissing);
@@ -59,6 +61,10 @@ public abstract class Playlist extends MediaLibraryItem {
         return mNbUnknown;
     }
 
+    public long getNbDurationUnknown() {
+        return mNbDurationUnknown;
+    }
+
     @Override
     public int getItemType() {
         return TYPE_PLAYLIST;
diff --git a/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java b/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
index 98ae29c86..670a95a3e 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/PlaylistImpl.java
@@ -11,8 +11,8 @@ import java.util.List;
 @SuppressWarnings("JniMissingFunction")
 public class PlaylistImpl extends Playlist {
 
-    public PlaylistImpl(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
-        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
+    public PlaylistImpl(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown, int nbDurationUnknown) {
+        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown, nbDurationUnknown);
     }
 
     public PlaylistImpl(Parcel in) {
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index e086d3604..b4aacadd6 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -341,7 +341,7 @@ public class StubMedialibrary extends Medialibrary {
     }
 
     public Playlist createPlaylist(String name, boolean includeMissing) {
-        Playlist playlist = MLServiceLocator.getAbstractPlaylist(dt.getUUID(), name, 0, 0L, 0, 0, 0);
+        Playlist playlist = MLServiceLocator.getAbstractPlaylist(dt.getUUID(), name, 0, 0L, 0, 0, 0, 0);
         dt.mPlaylists.add(playlist);
         onPlaylistsAdded();
         return playlist;
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
index 60181ff8f..4ed81c3bb 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubPlaylist.java
@@ -15,8 +15,8 @@ public class StubPlaylist extends Playlist {
     private ArrayList<Long> mTracksId = new ArrayList<>();
     private StubDataSource dt = StubDataSource.getInstance();
 
-    public StubPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown) {
-        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown);
+    public StubPlaylist(long id, String name, int trackCount, long duration, int nbVideo, int nbAudio, int nbUnknown, int nbDurationUnknown) {
+        super(id, name, trackCount, duration, nbVideo, nbAudio, nbUnknown, nbDurationUnknown);
     }
 
     public StubPlaylist(Parcel in) {



More information about the Android mailing list