[Android] MediaSession: Check if audio list is empty

Geoffrey Métais git at videolan.org
Wed Apr 10 11:07:20 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 10 11:06:04 2019 +0200| [80618c506f2b6247f50139a020548822cbe3440c] | committer: Geoffrey Métais

MediaSession: Check if audio list is empty

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

 vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 007717ecf..f46e204c5 100644
--- a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -55,13 +55,13 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
     override fun onPlayFromMediaId(mediaId: String, extras: Bundle?) {
         AppScope.launch {
             val context = playbackService.applicationContext
-            val ml = playbackService.medialibrary
             when {
                 mediaId == MediaSessionBrowser.ID_SHUFFLE_ALL -> {
-                    val count = context.getFromMl { ml.audioCount }
-                    val tracks = withContext(Dispatchers.IO) { ml.audio }
-                    playbackService.load(tracks, Random().nextInt(min(count, MEDIALIBRARY_PAGE_SIZE)))
-                    if (!playbackService.isShuffling) playbackService.shuffle()
+                    val tracks = context.getFromMl { audio }
+                    if (tracks.isNotEmpty()) {
+                        playbackService.load(tracks, Random().nextInt(min(tracks.size, MEDIALIBRARY_PAGE_SIZE)))
+                        if (!playbackService.isShuffling) playbackService.shuffle()
+                    }
                 }
                 mediaId.startsWith(MediaSessionBrowser.ALBUM_PREFIX) -> {
                     val tracks = context.getFromMl { getAlbum(mediaId.extractId())?.tracks }



More information about the Android mailing list