mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Fix crash while player is still buffering
This commit is contained in:
parent
e1667ab24f
commit
eb0dc21b6b
@ -134,20 +134,29 @@ class AudioPlayerFragment : BaseFragment() {
|
|||||||
*/
|
*/
|
||||||
private fun updateSeekBar() {
|
private fun updateSeekBar() {
|
||||||
val duration = playerService.getDuration()?.toFloat() ?: return
|
val duration = playerService.getDuration()?.toFloat() ?: return
|
||||||
|
|
||||||
|
// when the video is not loaded yet, retry in 100 ms
|
||||||
|
if (duration <= 0) {
|
||||||
|
handler.postDelayed(this::updateSeekBar, 100)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current position from the player service
|
||||||
val currentPosition = playerService.getCurrentPosition()?.toFloat() ?: 0f
|
val currentPosition = playerService.getCurrentPosition()?.toFloat() ?: 0f
|
||||||
|
|
||||||
// set the text for the indicators
|
// set the text for the indicators
|
||||||
binding.timeBar.valueTo = duration / 1000
|
|
||||||
binding.duration.text = DateUtils.formatElapsedTime((duration / 1000).toLong())
|
binding.duration.text = DateUtils.formatElapsedTime((duration / 1000).toLong())
|
||||||
|
binding.currentPosition.text = DateUtils.formatElapsedTime(
|
||||||
|
(currentPosition / 1000).toLong()
|
||||||
|
)
|
||||||
|
|
||||||
// update the time bar current value and maximum value
|
// update the time bar current value and maximum value
|
||||||
|
binding.timeBar.valueTo = duration / 1000
|
||||||
binding.timeBar.value = minOf(
|
binding.timeBar.value = minOf(
|
||||||
currentPosition / 1000,
|
currentPosition / 1000,
|
||||||
binding.timeBar.valueTo
|
binding.timeBar.valueTo
|
||||||
)
|
)
|
||||||
binding.currentPosition.text = DateUtils.formatElapsedTime(
|
|
||||||
(currentPosition / 1000).toLong()
|
|
||||||
)
|
|
||||||
handler.postDelayed(this::updateSeekBar, 200)
|
handler.postDelayed(this::updateSeekBar, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user