Android:进度更新 SeekrBar
我有一个媒体播放器的搜索栏,我的实现如下。
//SeekBar setup
progress = (SeekBar)findViewById(R.id.seekBarPlayer);
progress.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
mediaPlayer.seekTo(progress);
Log.v(TAG,progress +"Seeking...");
}
}
});
//seekbar initiated after mediaplayer initiated
total = mediaPlayer.getDuration();
progress.setMax(total);
但我的问题是seekBar 不会随着音乐播放而运行。它闲置在一处,如果我寻找,那么音乐就会寻找,但它不会运行或随着音乐一起前进。有人能告诉我我错过了什么吗?
预先感谢您的宝贵时间。
I'm having a seeker bar for media player and I have implemented as below.
//SeekBar setup
progress = (SeekBar)findViewById(R.id.seekBarPlayer);
progress.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
mediaPlayer.seekTo(progress);
Log.v(TAG,progress +"Seeking...");
}
}
});
//seekbar initiated after mediaplayer initiated
total = mediaPlayer.getDuration();
progress.setMax(total);
But my problem is seekBar doesn't run as the music plays. It idles at one place, if I seek then the music seeks but it doesn't run or make progress movment with the music. Can someone tell me what am I missing.
Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
线程对于这个来说太重了。这是我使用的精简版本。
在您的活动中声明一个处理程序,
一个可运行的程序
声明
在您的暂停中
a thread is too heavy for this. here is a cut down version of what i use.
declare a handler in your activity
declare a runnable
in your on resume
in your on pause
这是因为您在媒体播放器运行的同一线程中更新了进度栏。在 UI(或不同)线程中更新进度条。看看这个 android :如何使用进度条?。谢谢。
It is becoz you updated the progress bar in same thread in which media player runs. update your progress bar in UI (or different)thread.Look at this android: how do I use the progress bar?. Thnx.