Add force seek operations when loop one mode is enabled
This commit is contained in:
parent
d4c78dafae
commit
b50c54b1ed
3 changed files with 17 additions and 6 deletions
|
@ -75,6 +75,8 @@ import it.vfsfitvnm.vimusic.utils.broadCastPendingIntent
|
|||
import it.vfsfitvnm.vimusic.utils.exoPlayerDiskCacheMaxSizeKey
|
||||
import it.vfsfitvnm.vimusic.utils.findNextMediaItemById
|
||||
import it.vfsfitvnm.vimusic.utils.forcePlayFromBeginning
|
||||
import it.vfsfitvnm.vimusic.utils.forceSeekToNext
|
||||
import it.vfsfitvnm.vimusic.utils.forceSeekToPrevious
|
||||
import it.vfsfitvnm.vimusic.utils.getEnum
|
||||
import it.vfsfitvnm.vimusic.utils.intent
|
||||
import it.vfsfitvnm.vimusic.utils.isInvincibilityEnabledKey
|
||||
|
@ -778,8 +780,8 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||
private class SessionCallback(private val player: Player) : MediaSession.Callback() {
|
||||
override fun onPlay() = player.play()
|
||||
override fun onPause() = player.pause()
|
||||
override fun onSkipToPrevious() = player.seekToPrevious()
|
||||
override fun onSkipToNext() = player.seekToNext()
|
||||
override fun onSkipToPrevious() = player.forceSeekToPrevious()
|
||||
override fun onSkipToNext() = player.forceSeekToNext()
|
||||
override fun onSeekTo(pos: Long) = player.seekTo(pos)
|
||||
}
|
||||
|
||||
|
@ -788,8 +790,8 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||
when (intent.action) {
|
||||
Action.pause.value -> player.pause()
|
||||
Action.play.value -> player.play()
|
||||
Action.next.value -> player.seekToNext()
|
||||
Action.previous.value -> player.seekToPrevious()
|
||||
Action.next.value -> player.forceSeekToNext()
|
||||
Action.previous.value -> player.forceSeekToPrevious()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ import it.vfsfitvnm.vimusic.ui.components.SeekBar
|
|||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.favoritesIcon
|
||||
import it.vfsfitvnm.vimusic.utils.bold
|
||||
import it.vfsfitvnm.vimusic.utils.forceSeekToNext
|
||||
import it.vfsfitvnm.vimusic.utils.forceSeekToPrevious
|
||||
import it.vfsfitvnm.vimusic.utils.rememberRepeatMode
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
|
@ -197,7 +199,7 @@ fun Controls(
|
|||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(colorPalette.text),
|
||||
modifier = Modifier
|
||||
.clickable(onClick = binder.player::seekToPrevious)
|
||||
.clickable(onClick = binder.player::forceSeekToPrevious)
|
||||
.weight(1f)
|
||||
.size(24.dp)
|
||||
)
|
||||
|
@ -243,7 +245,7 @@ fun Controls(
|
|||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(colorPalette.text),
|
||||
modifier = Modifier
|
||||
.clickable(onClick = binder.player::seekToNext)
|
||||
.clickable(onClick = binder.player::forceSeekToNext)
|
||||
.weight(1f)
|
||||
.size(24.dp)
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package it.vfsfitvnm.vimusic.utils
|
||||
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.Timeline
|
||||
|
@ -51,6 +52,12 @@ fun Player.forcePlayAtIndex(mediaItems: List<MediaItem>, mediaItemIndex: Int) {
|
|||
fun Player.forcePlayFromBeginning(mediaItems: List<MediaItem>) =
|
||||
forcePlayAtIndex(mediaItems, 0)
|
||||
|
||||
fun Player.forceSeekToPrevious() =
|
||||
if (hasPreviousMediaItem()) seekToPrevious() else seekTo(mediaItemCount - 1, C.TIME_UNSET)
|
||||
|
||||
fun Player.forceSeekToNext() =
|
||||
if (hasNextMediaItem()) seekToNext() else seekTo(0, C.TIME_UNSET)
|
||||
|
||||
fun Player.addNext(mediaItem: MediaItem) {
|
||||
if (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED) {
|
||||
forcePlay(mediaItem)
|
||||
|
|
Loading…
Reference in a new issue