playback: expose goto to mediasession

Expose the ability to skip to an arbitrary item in the queue to the
MediaSession.
This commit is contained in:
OxygenCobalt 2022-07-25 13:44:31 -06:00
parent affa8c1c11
commit 496b72ca78
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 11 additions and 2 deletions

View file

@ -180,12 +180,14 @@ class MediaSessionComponent(
private fun updateQueue(queue: List<Song>) {
val queueItems =
queue.mapIndexed { i, song ->
// Since we usually have to load many songs into the queue, use the Cover URI
// instead of loading a bitmap.
val description =
MediaDescriptionCompat.Builder()
.setMediaId(song.id.toString())
.setTitle(song.resolveName(context))
.setSubtitle(song.resolveIndividualArtistName(context))
.setIconUri(song.album.coverUri) // Use lower-quality covers for speed
.setIconUri(song.album.coverUri)
.setMediaUri(song.uri)
.build()
@ -300,6 +302,12 @@ class MediaSessionComponent(
settings)
}
override fun onSkipToQueueItem(id: Long) {
if (id in playbackManager.queue.indices) {
playbackManager.goto(id.toInt())
}
}
override fun onStop() {
// Get the service to shut down with the ACTION_EXIT intent
context.sendBroadcast(Intent(PlaybackService.ACTION_EXIT))
@ -361,6 +369,7 @@ class MediaSessionComponent(
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE or
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or
PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM or
PlaybackStateCompat.ACTION_SEEK_TO or
PlaybackStateCompat.ACTION_STOP
}

View file

@ -184,7 +184,7 @@
<string name="set_save">Save playback state</string>
<string name="set_save_desc">Save the current playback state now</string>
<string name="set_wipe">Clear playback state</string>
<string name="set_wipe_desc">Wipe the previously saved playback state (if any)</string>
<string name="set_wipe_desc">Clear the previously saved playback state (if any)</string>
<string name="set_restore">Restore playback state</string>
<string name="set_restore_desc">Restore the previously saved playback state (if any)</string>
<string name="set_reindex">Reload music</string>