1.Ui刷新肯定是在主线程里进行刷新的,这里在handle里进行刷新
val handle:Handler = object :Handler(){
override fun handleMessage(msg: Message) {
super.handleMessage(msg)
if(msg.what==1){
ShowTime.setText(msg.obj as String)
}
}
}
2.不断递归调用本runnable
private var runnable = object :Runnable{
override fun run() {
var mediaPlayer = SingleTon.AudioSingleManager.getAudioSingleManager()
if(mediaPlayer!=null&&mediaPlayer.isPlaying){
var playeredTime = (mediaPlayer.currentPosition/1000).toLong()
var timeStr = getSongDurtationString((mediaPlayer.currentPosition).toLong())
var message = Message.obtain()
message.what = 100
message.obj = timeStr
handle.sendMessage(message)
}
handle.postDelayed(this,1000)
}
}
3.调用一下递归入口 handle.post(runnable)