mirror of
https://github.com/KRTirtho/spotube.git
synced 2026-08-05 19:59:51 +00:00
feat: add current time management in AudioPlayer for improved playback control
This commit is contained in:
parent
c10c9bb3fc
commit
9013b374c7
@ -309,6 +309,7 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent {
|
|||||||
val wasPlaying = _playerState.value == PlayerState.PLAYING
|
val wasPlaying = _playerState.value == PlayerState.PLAYING
|
||||||
val wasPaused = _playerState.value == PlayerState.PAUSED
|
val wasPaused = _playerState.value == PlayerState.PAUSED
|
||||||
val currentItem = _currentMediaItem.value
|
val currentItem = _currentMediaItem.value
|
||||||
|
val currentTimeMs = mediaPlayer.status().time().coerceAtLeast(0)
|
||||||
|
|
||||||
val rebuilt = if (enabled) {
|
val rebuilt = if (enabled) {
|
||||||
if (currentItem != null) {
|
if (currentItem != null) {
|
||||||
@ -331,7 +332,6 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent {
|
|||||||
|
|
||||||
val nextIndex = when {
|
val nextIndex = when {
|
||||||
currentItem == null -> if (currentPlaylist.isEmpty()) -1 else 0
|
currentItem == null -> if (currentPlaylist.isEmpty()) -1 else 0
|
||||||
enabled -> 0
|
|
||||||
else -> currentPlaylist.indexOfFirst { it.url == currentItem.url }
|
else -> currentPlaylist.indexOfFirst { it.url == currentItem.url }
|
||||||
.takeIf { it >= 0 } ?: 0
|
.takeIf { it >= 0 } ?: 0
|
||||||
}
|
}
|
||||||
@ -341,6 +341,9 @@ actual class AudioPlayer actual constructor(context: Any) : KoinComponent {
|
|||||||
|
|
||||||
if (nextIndex >= 0 && (wasPlaying || wasPaused)) {
|
if (nextIndex >= 0 && (wasPlaying || wasPaused)) {
|
||||||
mediaListPlayer.controls().play(nextIndex)
|
mediaListPlayer.controls().play(nextIndex)
|
||||||
|
if (currentTimeMs > 0) {
|
||||||
|
mediaPlayer.controls().setTime(currentTimeMs)
|
||||||
|
}
|
||||||
if (wasPaused) {
|
if (wasPaused) {
|
||||||
mediaListPlayer.controls().setPause(true)
|
mediaListPlayer.controls().setPause(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user