LibreTube/app/src/main/java/com/github/libretube/extensions/Player.kt

23 lines
610 B
Kotlin
Raw Normal View History

package com.github.libretube.extensions
import androidx.media3.common.Player
import com.github.libretube.helpers.PlayerHelper
fun Player.togglePlayPauseState() {
2023-10-23 21:25:09 +05:30
val minBufferingReached = totalBufferedDuration >= PlayerHelper.MINIMUM_BUFFER_DURATION ||
currentPosition + PlayerHelper.MINIMUM_BUFFER_DURATION >= duration
when {
playerError != null -> {
prepare()
play()
}
2023-09-10 18:06:29 +05:30
!isPlaying && playbackState == Player.STATE_ENDED -> {
seekTo(0)
}
!isPlaying && minBufferingReached -> play()
else -> pause()
}
2023-09-10 18:06:29 +05:30
}