Когда я останавливаю звук и перезапускаю с помощью playWhenReady, есть небольшая задержка относительно позиции. Например, позиция (когда я останавливаю звук) равна 1000. Но когда я перезапускаю изменение playWhenReady на true, позиция равна 2000. Из-за этого мой индикатор выполнения не движется плавно. Есть ли какое-нибудь решение по этому поводу?
if (activeHolder!! == holder) {
when (player!!.playWhenReady) {
true -> {
showLog("player!!.duration, playWhenReady true :"+player!!.duration)
showLog("player!!.currentPosition, playWhenReady true :"+player!!.currentPosition)
player!!.playWhenReady = false
handlerChangeProgress.removeCallbacks(updateChangeProgressTask)
showAudioStartButton(activeHolder!!)
return
}
false -> {
showLog("player!!.duration, playWhenReady false :"+player!!.duration)
showLog("player!!.currentPosition, playWhenReady false :"+player!!.currentPosition)
player!!.playWhenReady = true
handlerChangeProgress.postDelayed(updateChangeProgressTask, delayChangeProgress)
showAudioStopButton(activeHolder!!)
return
}
}
}
override fun onChangeProgressBar(progress: Float, currentPosition: Int, totalDuration: Int) {
if(player!!.playWhenReady) {
if (activeHolder?.adapterPosition == audioPosition) {
activeHolder?.let {
it.binding.progressBar.max = player!!.duration.toInt()
it.binding.progressBar.progress = player!!.currentPosition.toInt()
showAudioStopButton(it)
}
}
}
}
private val updateChangeProgressTask: Runnable = object : Runnable {
override fun run() {
if(player != null && changeProgressPlayerListener != null) {
val totalDuration: Long = player!!.duration
val currentPosition: Long = player!!.currentPosition
val progress = currentPosition.toFloat() / totalDuration.toFloat()
changeProgressPlayerListener!!.onChangeProgressBar(progress, currentPosition.toInt(), totalDuration.toInt())
}
handlerChangeProgress.postDelayed(this, delayChangeProgress)
}
}
Журнал
D/TAG: player!!.duration, playWhenReady false :4166
D/TAG: player!!.currentPosition, playWhenReady false :2459
D/TAG: player!!.duration, playWhenReady true :4166
D/TAG: player!!.currentPosition, playWhenReady true :2640