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