[Android] Play tracks in order of appearance in the menu
Robert Stone
git at videolan.org
Tue May 18 07:28:34 UTC 2021
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun May 16 22:17:35 2021 -0700| [a60bfb6d5dfcf29606409b1343205edf808985cb] | committer: Robert Stone
Play tracks in order of appearance in the menu
> https://code.videolan.org/videolan/vlc-android/commit/a60bfb6d5dfcf29606409b1343205edf808985cb
---
.../src/org/videolan/vlc/ArtworkProvider.kt | 47 ++++++----------------
.../src/org/videolan/vlc/MediaSessionCallback.kt | 2 +-
2 files changed, 14 insertions(+), 35 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt b/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
index 2b3891241..5c42f9169 100644
--- a/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/ArtworkProvider.kt
@@ -34,8 +34,6 @@ import android.util.LruCache
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.videolan.medialibrary.interfaces.Medialibrary
-import org.videolan.medialibrary.interfaces.media.Artist
-import org.videolan.medialibrary.interfaces.media.Genre
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.util.getFromMl
@@ -219,41 +217,22 @@ class ArtworkProvider : ContentProvider() {
}
private fun getPlayAllImage(ctx: Context, type: String, id: Long): ParcelFileDescriptor {
- var cover: Bitmap? = null
- val libraryItem: MediaLibraryItem? = runBlocking(Dispatchers.IO) {
- when (type) {
- GENRE -> ctx.getFromMl { getGenre(id) }
- ARTIST -> ctx.getFromMl { getArtist(id) }
- PLAYLIST -> ctx.getFromMl { getPlaylist(id) }
+ val bitmap = runBlocking(Dispatchers.IO) {
+ val tracks = when (type) {
+ GENRE -> ctx.getFromMl { getGenre(id)?.albums?.flatMap { it.tracks.toList() } }
+ ARTIST -> ctx.getFromMl { getArtist(id)?.tracks?.toList() }
+ PLAYLIST -> ctx.getFromMl { getPlaylist(id)?.tracks?.toList() }
else -> null
}
- }
- libraryItem?.let {
- runBlocking(Dispatchers.IO) {
- var iconAddition: Bitmap? = null
- var tracks: List<MediaWrapper>? = null
- if (libraryItem.itemType == MediaLibraryItem.TYPE_PLAYLIST) {
- tracks = libraryItem.tracks.toList()
- } else {
- val albums = when (libraryItem.itemType) {
- MediaLibraryItem.TYPE_ARTIST -> (libraryItem as Artist).albums
- MediaLibraryItem.TYPE_GENRE -> (libraryItem as Genre).albums
- else -> emptyArray()
- }
- if (albums.any { it.artworkMrl != null && it.artworkMrl.isNotEmpty() }) {
- tracks = libraryItem.tracks.toList()
- }
- iconAddition = ctx.getBitmapFromDrawable(R.drawable.ic_auto_playall_circle)
- }
- tracks?.let {
- cover = ThumbnailsProvider.getPlaylistImage("$type:${libraryItem.id}_256", tracks, 256, iconAddition)
- }
+ val cover = tracks?.let {
+ val iconAddition = if (type == PLAYLIST) null else ctx.getBitmapFromDrawable(R.drawable.ic_auto_playall_circle)
+ ThumbnailsProvider.getPlaylistImage("$type:${id}_256", tracks, 256, iconAddition)
+ }
+ return at runBlocking when {
+ cover != null -> cover
+ type == PLAYLIST -> ctx.getBitmapFromDrawable(R.drawable.ic_auto_playlist_unknown)
+ else -> ctx.getBitmapFromDrawable(R.drawable.ic_auto_playall)
}
- }
- val bitmap = when {
- cover != null -> cover
- type == PLAYLIST -> ctx.getBitmapFromDrawable(R.drawable.ic_auto_playlist_unknown)
- else -> ctx.getBitmapFromDrawable(R.drawable.ic_auto_playall)
}
return getPFDFromBitmap(bitmap)
}
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index f01e24ba0..9e64217fc 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -150,7 +150,7 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
if (isActive) tracks?.let { loadMedia(it.toList()) }
}
mediaId.startsWith(MediaSessionBrowser.GENRE_PREFIX) -> {
- val tracks = context.getFromMl { getGenre(mediaId.extractId())?.tracks }
+ val tracks = context.getFromMl { getGenre(mediaId.extractId())?.albums?.flatMap { it.tracks.toList() } }
if (isActive) tracks?.let { loadMedia(it.toList()) }
}
mediaId.startsWith(MediaSessionBrowser.PLAYLIST_PREFIX) -> {
More information about the Android
mailing list