在m中使用android搜索栏与播放和剩余时间为使用线程的songprgress处理程序的以下示例代码。每当我点击下一首/上一首歌时,它都会显示大整数值。如何解决这个问题?
class SongProgressUpdateThread extends Thread {
public void run() {
if (mp != null) {
int currentPosition = 0;
int total = mp.getDuration();
while (currentPosition < total && mp.isPlaying() && stopSongProgressThread==false ) {
try {
Thread.sleep(500);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
songProgress.setProgress(currentPosition);
showProgress(currentPosition, total);
}
}
}
}
private void showProgress(int currentPosition, int duration) {
Bundle bundle = new Bundle();
bundle.putString("playedTime", getPlayedTime(currentPosition));
bundle.putString("remainingTime",getRemainigTime(currentPosition, duration));
Message msg = new Message();
msg.setData(bundle);
songProgresshandler.sendMessage(msg);
}
Handler songProgresshandler = new Handler() {
public void handleMessage(Message message) {
final Bundle b = message.getData();
playedTime.setText(b.getString("playedTime"));
remainingTime.setText("-" + b.getString("remainingTime"));
}
};
答案 0 :(得分:0)
也许您可以尝试使用VideoView和MediaController来完成它。 如:
VideoView vv = (VideoView)this.findViewById(R.id.videoview);
Uri uri = Uri.parse(path);
MediaController mediaController = new MediaController(this);
mediaController.setMediaPlayer(vv);
vv.setVideoURI(uri);
vv.setMediaController(mediaController);
vv.start();
mediaController.show();
答案 1 :(得分:0)
单击“下一个/上一个”按钮时您做了什么 也许mediaPlayer处于无效状态,看LogCat里面的任何错误信息?(比如“无效的stauts中的”getDuration()“)