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:
parent
affa8c1c11
commit
496b72ca78
2 changed files with 11 additions and 2 deletions
|
@ -180,12 +180,14 @@ class MediaSessionComponent(
|
||||||
private fun updateQueue(queue: List<Song>) {
|
private fun updateQueue(queue: List<Song>) {
|
||||||
val queueItems =
|
val queueItems =
|
||||||
queue.mapIndexed { i, song ->
|
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 =
|
val description =
|
||||||
MediaDescriptionCompat.Builder()
|
MediaDescriptionCompat.Builder()
|
||||||
.setMediaId(song.id.toString())
|
.setMediaId(song.id.toString())
|
||||||
.setTitle(song.resolveName(context))
|
.setTitle(song.resolveName(context))
|
||||||
.setSubtitle(song.resolveIndividualArtistName(context))
|
.setSubtitle(song.resolveIndividualArtistName(context))
|
||||||
.setIconUri(song.album.coverUri) // Use lower-quality covers for speed
|
.setIconUri(song.album.coverUri)
|
||||||
.setMediaUri(song.uri)
|
.setMediaUri(song.uri)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
@ -300,6 +302,12 @@ class MediaSessionComponent(
|
||||||
settings)
|
settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSkipToQueueItem(id: Long) {
|
||||||
|
if (id in playbackManager.queue.indices) {
|
||||||
|
playbackManager.goto(id.toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
// Get the service to shut down with the ACTION_EXIT intent
|
// Get the service to shut down with the ACTION_EXIT intent
|
||||||
context.sendBroadcast(Intent(PlaybackService.ACTION_EXIT))
|
context.sendBroadcast(Intent(PlaybackService.ACTION_EXIT))
|
||||||
|
@ -361,6 +369,7 @@ class MediaSessionComponent(
|
||||||
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE or
|
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE or
|
||||||
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
|
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
|
||||||
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or
|
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or
|
||||||
|
PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM or
|
||||||
PlaybackStateCompat.ACTION_SEEK_TO or
|
PlaybackStateCompat.ACTION_SEEK_TO or
|
||||||
PlaybackStateCompat.ACTION_STOP
|
PlaybackStateCompat.ACTION_STOP
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
<string name="set_save">Save playback state</string>
|
<string name="set_save">Save playback state</string>
|
||||||
<string name="set_save_desc">Save the current playback state now</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">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">Restore playback state</string>
|
||||||
<string name="set_restore_desc">Restore the previously saved playback state (if any)</string>
|
<string name="set_restore_desc">Restore the previously saved playback state (if any)</string>
|
||||||
<string name="set_reindex">Reload music</string>
|
<string name="set_reindex">Reload music</string>
|
||||||
|
|
Loading…
Reference in a new issue