playback: add missing session actions

This commit is contained in:
Alexander Capehart 2024-08-28 13:29:24 -06:00
parent 916c3c46df
commit 44f9617307
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -29,6 +29,9 @@ class MediaSessionInterface @Inject constructor(
private val commandFactory: PlaybackCommand.Factory,
private val musicRepository: MusicRepository,
) : MediaSessionCompat.Callback() {
override fun onPrepare() {
super.onPrepare()
}
override fun onPrepareFromMediaId(mediaId: String?, extras: Bundle?) {
super.onPrepareFromMediaId(mediaId, extras)
@ -127,13 +130,15 @@ class MediaSessionInterface @Inject constructor(
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
else -> RepeatMode.NONE
})
}
)
}
override fun onSetShuffleMode(shuffleMode: Int) {
playbackManager.shuffled(
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP)
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP
)
}
override fun onSkipToQueueItem(id: Long) {
@ -159,10 +164,12 @@ class MediaSessionInterface @Inject constructor(
is MediaSessionUID.SingleItem -> {
music = musicRepository.find(uid.uid) ?: return null
}
is MediaSessionUID.ChildItem -> {
music = musicRepository.find(uid.childUid) ?: return null
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
}
else -> return null
}
@ -180,14 +187,17 @@ class MediaSessionInterface @Inject constructor(
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
}
companion object {
const val ACTIONS =
PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID or
PlaybackStateCompat.ACTION_PLAY or
PlaybackStateCompat.ACTION_PAUSE or
PlaybackStateCompat.ACTION_PLAY_PAUSE or
@ -197,6 +207,7 @@ class MediaSessionInterface @Inject constructor(
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or
PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM or
PlaybackStateCompat.ACTION_SEEK_TO or
PlaybackStateCompat.ACTION_REWIND or
PlaybackStateCompat.ACTION_STOP
}
}