I wanna connect my media player to the progress bar Here is my code :
var media55 :MediaPlayer
var progressBar55 :ProgressBar
progressBar55=findViewById(R.id.progressBar)
media55 = MediaPlayer()
media55.setDataSource("SONG URL HERE")
media55.prepare()
I wanna when I start media player the progress bar progress with the media player
Define Handler in class scope.
private val handler = Handler()
Then set your ProgressBar max value to duration of the MediaPlayer data source.
progressBar55.max = media55.duration
Finally add a Runnable object to set progress on your ProgressBar every X milliseconds.
val interval: Long = 1000
val statusChecker = object : Runnable {
override fun run() {
progressBar.progress = media.currentPosition
handler.postDelayed(this, interval)
}
}
When you run your audio you should call statusChecker.run()
to start updating porgress, and when you are done remove Handler callbacks by calling handler.removeCallbacksAndMessages(null)