[Android] Playlists: fix media not set over ML_SIZE_LIMIT

Duncan McNamara git at videolan.org
Mon Aug 8 07:07:10 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri Aug  5 11:16:58 2022 +0200| [c6ae7d32f2f9a09cfc41e2ff61dcf162263afa46] | committer: Nicolas Pomepuy

Playlists: fix media not set over ML_SIZE_LIMIT

With pagedLists when a list is over the MEDIALIBRARY_SIZE_LIMIT,
media over it won't be set, causing crashes. This forces each media to
be set when the mediawrapper list is over the constant.

Fixes #2623

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

 .../src/org/videolan/vlc/media/MediaUtils.kt        | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 4bb126162..cd69ef704 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -187,7 +187,26 @@ object MediaUtils {
     }
 
     fun playTracks(context: Context, provider: MedialibraryProvider<MediaWrapper>, position: Int, shuffle: Boolean = false) = context.scope.launch {
-        withContext(Dispatchers.IO) { provider.pagedList }.value?.let { openList(context, it.toList(), position, shuffle) }
+        SuspendDialogCallback(context) {
+            withContext(Dispatchers.IO) {
+                val list = when (val count = provider.getTotalCount()) {
+                    0 -> listOf()
+                    in 1..MEDIALIBRARY_PAGE_SIZE -> provider.pagedList.value ?: listOf()
+                    else -> mutableListOf<MediaWrapper>().apply {
+                        var index = 0
+                        while (index < count) {
+                            val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count - index)
+                            val page = provider.getPage(pageCount, index)
+                            for (item in page) addAll(item.tracks)
+                            index += pageCount
+                        }
+                    }
+                }
+                list.takeIf { it.isNotEmpty() }?.let {
+                    openList(context, it, position, shuffle)
+                }
+            }
+        }
     }
 
     fun playAlbums(context: Context?, provider: MedialibraryProvider<Album>, position: Int, shuffle: Boolean) {



More information about the Android mailing list