WEB开发网
开发学院手机开发Android 开发 Android 开发之音乐播放之进度条 阅读

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.radi

< /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) {

上一页  1 2 3 4  下一页

Tags:Android 开发 音乐

编辑录入:coldstar [复制链接] [打 印]
赞助商链接