From 4fbadc7c1ea2d588c19983ebe8cc2c3ed56eac66 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Tue, 1 Nov 2022 08:19:44 +0100 Subject: [PATCH] Implement more media session callbacks --- .../it/vfsfitvnm/vimusic/service/PlayerService.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt index e66be47..2321e30 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt @@ -37,6 +37,7 @@ import androidx.core.net.toUri import androidx.core.text.isDigitsOnly import androidx.media3.common.AudioAttributes import androidx.media3.common.C +import androidx.media3.common.IllegalSeekPositionException import androidx.media3.common.MediaItem import androidx.media3.common.PlaybackException import androidx.media3.common.Player @@ -382,7 +383,7 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene .setSubtitle(mediaItem.mediaMetadata.artist) .setIconUri(mediaItem.mediaMetadata.artworkUri) .build(), - index.toLong() + (index + startIndex).toLong() ) } ) @@ -957,6 +958,13 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene override fun onSkipToPrevious() = player.forceSeekToPrevious() override fun onSkipToNext() = player.forceSeekToNext() override fun onSeekTo(pos: Long) = player.seekTo(pos) + override fun onStop() = player.pause() + override fun onRewind() = player.seekToDefaultPosition() + + override fun onSkipToQueueItem(id: Long) = try { + player.seekToDefaultPosition(id.toInt()) + } catch (_: IllegalSeekPositionException) { + } } private class NotificationActionReceiver(private val player: Player) : BroadcastReceiver() {