//播放进度条
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if (fromUser==true) {
mediaPlayer.seekTo(progress);
nowPlayTime.setText(ShowTime(progress));
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
//音量进度条
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if (fromUser) {
int SeekPosition=seekBar.getProgress();
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, SeekPosition, 0);
}
volumeView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
//时间显示函数,我们获得音乐信息的是以毫秒为单位的,把把转换成我们熟悉的00:00格式
public String ShowTime(int time){
time/=1000;
int minute=time/60;
int hour=minute/60;
int second=time%60;
minute%=60;
return String.format("%02d:%02d", minute, second);
}
Handler handler=new Handler();
public void StrartbarUpdate(){
handler.post(r);
}
Runnable r=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
int CurrentPosition=mediaPlayer.getCurrentPosition();
nowPlayTime.setText(ShowTime(CurrentPosition));
int mMax=mediaPlayer.getDuration();
ProceseekBar2.setMax(mMax);
ProceseekBar2.setProgress(CurrentPosition);
handler.postDelayed(r, 100);
}
};
}
//把一个名字为test.mp3的文件上传到系统中去,你们懂的.....
00:37 当前播放时间
04:16音乐总时间
11 当前音量
15 总音量