From 44f9617307ed42003845f1f8fadce0964da0ddef Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 28 Aug 2024 13:29:24 -0600 Subject: [PATCH] playback: add missing session actions --- .../playback/service/MediaSessionInterface.kt | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionInterface.kt b/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionInterface.kt index 2b0a45769..65b55b51f 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionInterface.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionInterface.kt @@ -24,11 +24,14 @@ import org.oxycblt.auxio.playback.state.ShuffleMode import javax.inject.Inject class MediaSessionInterface @Inject constructor( - @ApplicationContext private val context: Context, + @ApplicationContext private val context: Context, private val playbackManager: PlaybackStateManager, 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 } @@ -179,16 +186,19 @@ class MediaSessionInterface @Inject constructor( when (parent) { is Album -> commandFactory.songFromAlbum(music, 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) - ?: commandFactory.songFromGenre(music, music.genres[0], 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 or + PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID or + PlaybackStateCompat.ACTION_PLAY or PlaybackStateCompat.ACTION_PAUSE or PlaybackStateCompat.ACTION_PLAY_PAUSE or PlaybackStateCompat.ACTION_SET_REPEAT_MODE 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 } -} \ No newline at end of file +}