mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Improve behavior when seeking to next video
This commit is contained in:
parent
f2fce67454
commit
c3b08ef5f6
@ -179,25 +179,24 @@ class AudioPlayerFragment : BaseFragment() {
|
|||||||
* Update the position, duration and text views belonging to the seek bar
|
* Update the position, duration and text views belonging to the seek bar
|
||||||
*/
|
*/
|
||||||
private fun updateSeekBar() {
|
private fun updateSeekBar() {
|
||||||
val duration = playerService?.getDuration()?.toFloat() ?: return
|
val duration = playerService?.getDuration()?.takeIf { it > 0 } ?: let {
|
||||||
|
// if there's no duration available, clear everything
|
||||||
// when the video is not loaded yet, retry in 100 ms
|
binding.timeBar.value = 0f
|
||||||
if (duration <= 0) {
|
binding.duration.text = ""
|
||||||
|
binding.currentPosition.text = ""
|
||||||
handler.postDelayed(this::updateSeekBar, 100)
|
handler.postDelayed(this::updateSeekBar, 100)
|
||||||
return
|
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.duration.text = DateUtils.formatElapsedTime((duration / 1000).toLong())
|
binding.duration.text = DateUtils.formatElapsedTime(duration / 1000)
|
||||||
binding.currentPosition.text = DateUtils.formatElapsedTime(
|
binding.currentPosition.text = DateUtils.formatElapsedTime(
|
||||||
(currentPosition / 1000).toLong()
|
(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.valueTo = (duration / 1000).toFloat()
|
||||||
binding.timeBar.value = minOf(
|
binding.timeBar.value = minOf(
|
||||||
currentPosition / 1000,
|
currentPosition / 1000,
|
||||||
binding.timeBar.valueTo
|
binding.timeBar.valueTo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user