Android 开发之音乐播放之进度条
2010-04-12 19:05:00 来源:WEB开发网< /LinearLayout >
2. View 初始化
Java代码
1. public void initialize(){
2.
3. sBar = (SeekBar)findViewById(R.id.seekb);
4. rGroup = (RadioGroup)findViewById(R.id.radio);
5. cmdButton = (Button)findViewById(R.id.cmd);
6.
7. mPlayer = new MediaPlayer();
8. }
public void initialize(){
sBar = (SeekBar)findViewById(R.id.seekb);
rGroup = (RadioGroup)findViewById(R.id.radio);
cmdButton = (Button)findViewById(R.id.cmd);
mPlayer = new MediaPlayer();
}
3. 拖动SeekBar 且播放指定位置的音乐
Java代码
1. sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
2.
3. @Override
4. public void onProgressChanged(SeekBar seekBar, int progress,
5. boolean fromUser) {
6. // TODO Auto-generated method stub
7.
8. }
9.
10. @Override
11. public void onStartTrackingTouch(SeekBar seekBar) {
12. // TODO Auto-generated method stub
13. }
14.
15. @Override
16. public void onStopTrackingTouch(SeekBar seekBar) {
17. // TODO Auto-generated method stub
18. int dest = seekBar.getProgress();
19.
20. int mMax = mPlayer.getDuration();
21. int sMax = sBar.getMax();
22.
23. mPlayer.seekTo(mMax*dest/sMax);
24.
25. }
26.
27. });
sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
更多精彩
赞助商链接