[Android] Display cover art and artist in playback queue. Set description to album name for bluetooth headunits.
Robert Stone
git at videolan.org
Mon Oct 19 08:50:41 CEST 2020
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Thu Oct 15 22:11:30 2020 -0700| [cd5d663e8ddc623cb3a234ed01214cf49b84d5c0] | committer: Nicolas Pomepuy
Display cover art and artist in playback queue. Set description to album name for bluetooth headunits.
> https://code.videolan.org/videolan/vlc-android/commit/cd5d663e8ddc623cb3a234ed01214cf49b84d5c0
---
application/vlc-android/src/org/videolan/vlc/FileProvider.kt | 6 +++++-
.../vlc-android/src/org/videolan/vlc/PlaybackService.kt | 11 ++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/FileProvider.kt b/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
index ecbd105077..dff811fbc1 100644
--- a/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
@@ -32,7 +32,7 @@ class FileProvider : ContentProvider() {
if (path.contains("..")) throw SecurityException("Illegal access")
val file = File(path)
val canonicalPath = file.canonicalPath
- if (!AndroidDevices.mountBL.any { canonicalPath.startsWith(it) }) throw SecurityException("Illegal access")
+ if (!isPathValid(canonicalPath)) throw SecurityException("Illegal access")
if (file.exists()) {
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
}
@@ -45,3 +45,7 @@ fun getFileUri(path: String) = Uri.Builder()
.authority(THUMB_PROVIDER_AUTHORITY)
.path(path)
.build()!!
+
+fun isPathValid(path: String): Boolean {
+ return AndroidDevices.mountBL.any { path.startsWith(it) }
+}
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 500bcc4106..023c572925 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -42,6 +42,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.getSystemService
+import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
@@ -1079,14 +1080,18 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
private fun updateMediaQueue() = lifecycleScope.launch(start = CoroutineStart.UNDISPATCHED) {
if (!this at PlaybackService::mediaSession.isInitialized) initMediaSession()
val ctx = this at PlaybackService
+ val defaultCoverUri = "android.resource://${BuildConfig.APP_ID}/drawable/${R.drawable.ic_no_song}".toUri()
val queue = withContext(Dispatchers.Default) {
LinkedList<MediaSessionCompat.QueueItem>().also {
for ((position, media) in playlistManager.getMediaList().withIndex()) {
val title: String = media.nowPlaying ?: media.title
+ val coverUri = if (!media.artworkMrl.isNullOrEmpty() && isPathValid(media.artworkMrl))
+ getFileUri(media.artworkMrl) else defaultCoverUri
val builder = MediaDescriptionCompat.Builder()
- builder.setTitle(title)
- .setDescription(getMediaDescription(MediaUtils.getMediaArtist(ctx, media), MediaUtils.getMediaAlbum(ctx, media)))
- .setIconBitmap(BitmapUtil.getPictureFromCache(media))
+ .setTitle(title)
+ .setSubtitle(MediaUtils.getMediaArtist(ctx, media))
+ .setDescription(MediaUtils.getMediaAlbum(ctx, media))
+ .setIconUri(coverUri)
.setMediaUri(media.uri)
.setMediaId(MediaSessionBrowser.generateMediaId(media))
it.add(MediaSessionCompat.QueueItem(builder.build(), position.toLong()))
More information about the Android
mailing list