Skip to content
Snippets Groups Projects
Commit 6a047a0c authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

MediaSession: Check if audio list is empty

(cherry picked from commit 80618c50)
parent ecab21b7
No related branches found
No related tags found
No related merge requests found
......@@ -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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment