You just create a handler, that repeats and sets the seekbar. Put this code into the onCreate function.
val handler = Handler(Looper.getMainLooper())
runOnUiThread(object : Runnable {
override fun run() {
seekbar?.setProgress(vidView!!.currentPosition)
handler.postDelayed(this, 1000) //Set the update time
}
}
The 1000 milliseconds is just a example, if you want to have your seekbar update faster you should use a smaller delay.
I did it myself, it is the best compromise between a live seekbar and the performance. You can also edit the delay for a faster update.
But keep in mind to add a check into the onProgressChanged
like if(p2) { }
so that the progress only changes if the user changes the progress and not the system itself.
Like that:
override fun onProgressChanged(p0:SeekBar, p1:Int, p2:Boolean)
{
if(p2) {
seekbar?.progress?.let { vidView?.seekTo(it) }
val p1_sec = (p1/1000).toInt()
val p1_minute = (p1_sec/60).toInt()
val p1_second = p1_sec%60
current_time?.text = p1_minute.toString()+":"+p1_second.toString()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…