问题描述
- listview ProgressBar
-
你好,我做的是实现播放音频文件的,每一个音频文件都有对应的ProgressBar,还有播放暂停,怎么更新progressBar的进度呢
解决方案
写一个线程,handler发消息更新进度!
解决方案二:
private final class ProgressThread extends Thread{
@Override
public void run() {
while(true){
//获取当前播放进度
currentPosition = player.getCurrentPosition();
//发消息
Message msg = handler.obtainMessage();
msg.what = MESSAGE_UPDATE_PROGRESS ;
handler.sendMessage(msg);
try {
Thread.sleep(800);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private final class InnerHandlerCallback implements Handler.Callback{
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_UPDATE_PROGRESS:
int musicDuration = player.getDuration();
int progress = currentPosition*100/musicDuration;
progressBar.setProgress(progress);
if(player.isPlaying()){
currentPositionTextView.setText(getTime(currentPosition));
durationTextView.setText(getTime(musicDuration));
titleTextView.setText(new File(path).getName());
}
break;
}
return true;
}
这是之前我写过的一个音乐播放器,上面发消息,下面接收并更新进度!
解决方案三:
获取播放音频的控件,一般都有进度信息,然后更新
时间: 2024-10-29 13:16:03