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

20 lines
397 B
Kotlin
Raw Normal View History

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