另一件事是seekBar的计时器,它在音频文件的持续时间内问题是音频文件做(迷你)每1秒停止一次如何让搜索栏每秒更新一次而不做任何停止< / p>
seekBar2.setMax(mediaPlayer.getDuration());
seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mediaPlayer.seekTo(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
seekBar2.setProgress(mediaPlayer.getCurrentPosition());
}
},0,1000);
public void reset(View v) {
mediaPlayer.reset();
}
答案 0 :(得分:0)
尝试此操作以重置您的mediaPlayer
public void reset(View v) {
mediaPlayer.seekTo(0);
mediaPlayer.start();
}
尝试此操作以更新搜索栏
private Handler mHandler = new Handler();
//you have to update Seekbar on UI thread
Your.Activity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if(mediaPlayer != null){
int mCurrentPosition = mediaPlayer.getCurrentPosition() / 1000;
seekBar2.setProgress(mCurrentPosition);
}
mHandler.postDelayed(this, 1000);
}
});
当用户拖动
MediaPlayer
使用以下代码时,您需要更新SeekBar
的位置
seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(mediaPlayer != null && fromUser){
mediaPlayer.seekTo(progress * 1000);
}
}
});