[Android] Update mediasession queue in background
Geoffrey Métais
git at videolan.org
Fri Feb 15 15:56:54 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 15 15:56:12 2019 +0100| [119b0f2576723c72f813488bca262efde91895a4] | committer: Geoffrey Métais
Update mediasession queue in background
> https://code.videolan.org/videolan/vlc-android/commit/119b0f2576723c72f813488bca262efde91895a4
---
.../src/org/videolan/vlc/PlaybackService.kt | 41 ++++++++++++----------
.../src/org/videolan/vlc/media/PlaylistManager.kt | 1 -
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index e26abc6ac..a97c20125 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -934,12 +934,12 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
val media = playlistManager.getCurrentMedia()
if (media == null || isVideoPlaying) return
launch(Dispatchers.Default) { sendBroadcast(Intent("com.android.music.metachanged")
- .putExtra("track", media.title)
- .putExtra("artist", media.artist)
- .putExtra("album", media.album)
- .putExtra("duration", media.length)
- .putExtra("playing", isPlaying)
- .putExtra("package", "org.videolan.vlc"))
+ .putExtra("track", media.title)
+ .putExtra("artist", media.artist)
+ .putExtra("album", media.album)
+ .putExtra("duration", media.length)
+ .putExtra("playing", isPlaying)
+ .putExtra("package", "org.videolan.vlc"))
}
}
@@ -1009,19 +1009,22 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
@MainThread
fun load(mediaList: List<MediaWrapper>, position: Int) = playlistManager.load(mediaList, position)
- private fun updateMediaQueue() {
- val queue = LinkedList<MediaSessionCompat.QueueItem>()
- var position = -1L
- for (media in playlistManager.getMediaList()) {
- var title: String? = media.nowPlaying
- if (title == null) title = media.title
- val builder = MediaDescriptionCompat.Builder()
- builder.setTitle(title)
- .setDescription(Util.getMediaDescription(MediaUtils.getMediaArtist(this, media), MediaUtils.getMediaAlbum(this, media)))
- .setIconBitmap(BitmapUtil.getPictureFromCache(media))
- .setMediaUri(media.uri)
- .setMediaId(BrowserProvider.generateMediaId(media))
- queue.add(MediaSessionCompat.QueueItem(builder.build(), ++position))
+ private fun updateMediaQueue() = launch {
+ val ctx = this at PlaybackService
+ val queue = withContext(Dispatchers.Default) {
+ LinkedList<MediaSessionCompat.QueueItem>().also {
+ for ((position, media) in playlistManager.getMediaList().withIndex()) {
+ var title: String? = media.nowPlaying
+ if (title == null) title = media.title
+ val builder = MediaDescriptionCompat.Builder()
+ builder.setTitle(title)
+ .setDescription(Util.getMediaDescription(MediaUtils.getMediaArtist(ctx, media), MediaUtils.getMediaAlbum(ctx, media)))
+ .setIconBitmap(BitmapUtil.getPictureFromCache(media))
+ .setMediaUri(media.uri)
+ .setMediaId(BrowserProvider.generateMediaId(media))
+ it.add(MediaSessionCompat.QueueItem(builder.build(), position.toLong()))
+ }
+ }
}
mediaSession.setQueue(queue)
}
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 9f41e526d..1448b7afe 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -607,7 +607,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
}
}
-
}
ret = index
}
More information about the Android
mailing list