[Android] Use max item count to speed up recent audio query

Robert Stone git at videolan.org
Tue May 11 06:27:09 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun May  9 21:48:53 2021 -0700| [395787c6450197d4388968b780fa5a4d54d7d42b] | committer: Nicolas Pomepuy

Use max item count to speed up recent audio query

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

 .../vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt      | 8 ++++----
 .../vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 5937099cf..f01e24ba0 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -11,6 +11,7 @@ import android.view.KeyEvent
 import androidx.core.net.toUri
 import androidx.lifecycle.lifecycleScope
 import kotlinx.coroutines.*
+import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.AndroidDevices
@@ -128,10 +129,9 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                     }
                 }
                 mediaId == MediaSessionBrowser.ID_LAST_ADDED -> {
-                    val tracks = context.getFromMl { recentAudio?.toList() }
-                    if (!tracks.isNullOrEmpty() && isActive) {
-                        val mediaList = tracks.subList(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
-                        loadMedia(mediaList)
+                    val tracks = context.getFromMl { getPagedAudio(Medialibrary.SORT_INSERTIONDATE, true, MediaSessionBrowser.MAX_HISTORY_SIZE, 0) }
+                    if (tracks.isNotEmpty() && isActive) {
+                        loadMedia(tracks.toList())
                     }
                 }
                 mediaId == MediaSessionBrowser.ID_HISTORY -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
index 22f800bf3..751103165 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -250,8 +250,8 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                                 .build()
                         results.add(MediaBrowserCompat.MediaItem(shuffleAllMediaDesc, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE))
                         /* Last Added */
-                        val recentAudio = ml.recentAudio
-                        val recentAudioSize = recentAudio.size.coerceAtMost(MAX_HISTORY_SIZE)
+                        val recentAudio = ml.getPagedAudio(Medialibrary.SORT_INSERTIONDATE, true, MAX_HISTORY_SIZE, 0)
+                        val recentAudioSize = recentAudio.size
                         val lastAddedPath = if (recentAudioSize > 0) {
                             Uri.Builder()
                                     .appendPath(ArtworkProvider.LAST_ADDED)
@@ -321,9 +321,9 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                     ID_STREAMS -> list = ml.lastStreamsPlayed()
                     ID_LAST_ADDED -> {
                         limitSize = true
-                        list = ml.recentAudio
+                        list = ml.getPagedAudio(Medialibrary.SORT_INSERTIONDATE, true, MAX_HISTORY_SIZE, 0)
                         if (list != null && list.size > 1) {
-                            val playAllMediaDesc = getPlayAllBuilder(res, parentId, list.size.coerceAtMost(MAX_HISTORY_SIZE)).build()
+                            val playAllMediaDesc = getPlayAllBuilder(res, parentId, list.size).build()
                             results.add(MediaBrowserCompat.MediaItem(playAllMediaDesc, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE))
                         }
                     }



More information about the Android mailing list