playback: add missing session actions
This commit is contained in:
parent
916c3c46df
commit
44f9617307
1 changed files with 18 additions and 7 deletions
|
@ -29,6 +29,9 @@ class MediaSessionInterface @Inject constructor(
|
||||||
private val commandFactory: PlaybackCommand.Factory,
|
private val commandFactory: PlaybackCommand.Factory,
|
||||||
private val musicRepository: MusicRepository,
|
private val musicRepository: MusicRepository,
|
||||||
) : MediaSessionCompat.Callback() {
|
) : MediaSessionCompat.Callback() {
|
||||||
|
override fun onPrepare() {
|
||||||
|
super.onPrepare()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPrepareFromMediaId(mediaId: String?, extras: Bundle?) {
|
override fun onPrepareFromMediaId(mediaId: String?, extras: Bundle?) {
|
||||||
super.onPrepareFromMediaId(mediaId, extras)
|
super.onPrepareFromMediaId(mediaId, extras)
|
||||||
|
@ -127,13 +130,15 @@ class MediaSessionInterface @Inject constructor(
|
||||||
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
|
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
|
||||||
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
|
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
|
||||||
else -> RepeatMode.NONE
|
else -> RepeatMode.NONE
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSetShuffleMode(shuffleMode: Int) {
|
override fun onSetShuffleMode(shuffleMode: Int) {
|
||||||
playbackManager.shuffled(
|
playbackManager.shuffled(
|
||||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
|
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
|
||||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP)
|
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSkipToQueueItem(id: Long) {
|
override fun onSkipToQueueItem(id: Long) {
|
||||||
|
@ -159,10 +164,12 @@ class MediaSessionInterface @Inject constructor(
|
||||||
is MediaSessionUID.SingleItem -> {
|
is MediaSessionUID.SingleItem -> {
|
||||||
music = musicRepository.find(uid.uid) ?: return null
|
music = musicRepository.find(uid.uid) ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
is MediaSessionUID.ChildItem -> {
|
is MediaSessionUID.ChildItem -> {
|
||||||
music = musicRepository.find(uid.childUid) ?: return null
|
music = musicRepository.find(uid.childUid) ?: return null
|
||||||
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
|
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,14 +187,17 @@ class MediaSessionInterface @Inject constructor(
|
||||||
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
|
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
|
||||||
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
|
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
|
||||||
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
|
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
|
||||||
|
|
||||||
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
|
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
|
||||||
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
|
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
|
||||||
|
|
||||||
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
|
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
|
||||||
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
|
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ACTIONS =
|
const val ACTIONS =
|
||||||
|
PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID or
|
||||||
PlaybackStateCompat.ACTION_PLAY or
|
PlaybackStateCompat.ACTION_PLAY or
|
||||||
PlaybackStateCompat.ACTION_PAUSE or
|
PlaybackStateCompat.ACTION_PAUSE or
|
||||||
PlaybackStateCompat.ACTION_PLAY_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_PREVIOUS or
|
||||||
PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM or
|
PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM or
|
||||||
PlaybackStateCompat.ACTION_SEEK_TO or
|
PlaybackStateCompat.ACTION_SEEK_TO or
|
||||||
|
PlaybackStateCompat.ACTION_REWIND or
|
||||||
PlaybackStateCompat.ACTION_STOP
|
PlaybackStateCompat.ACTION_STOP
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue