Android seekbar播放时间和剩余时间显示大整数值。?
在m中,使用带play的android seekbar和以下带thread的songprgress处理程序示例代码的剩余时间。每当我点击下一首/上一首歌时,它都会显示大的整数值。如何解决这个问题Android seekbar播放时间和剩余时间显示大整数值。?,android,Android,在m中,使用带play的android seekbar和以下带thread的songprgress处理程序示例代码的剩余时间。每当我点击下一首/上一首歌时,它都会显示大的整数值。如何解决这个问题 class SongProgressUpdateThread extends Thread { public void run() { if (mp != null) { int currentPosition = 0; int
class SongProgressUpdateThread extends Thread {
public void run() {
if (mp != null) {
int currentPosition = 0;
int total = mp.getDuration();
while (currentPosition < total && mp.isPlaying() && stopSongProgressThread==false ) {
try {
Thread.sleep(500);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
songProgress.setProgress(currentPosition);
showProgress(currentPosition, total);
}
}
}
}
private void showProgress(int currentPosition, int duration) {
Bundle bundle = new Bundle();
bundle.putString("playedTime", getPlayedTime(currentPosition));
bundle.putString("remainingTime",getRemainigTime(currentPosition, duration));
Message msg = new Message();
msg.setData(bundle);
songProgresshandler.sendMessage(msg);
}
Handler songProgresshandler = new Handler() {
public void handleMessage(Message message) {
final Bundle b = message.getData();
playedTime.setText(b.getString("playedTime"));
remainingTime.setText("-" + b.getString("remainingTime"));
}
};
类SongProgressUpdateThread扩展线程{
公开募捐{
如果(mp!=null){
int currentPosition=0;
int total=mp.getDuration();
while(currentPosition
也许您可以尝试使用VideoView和MediaController来实现这一点。
例如:
class SongProgressUpdateThread extends Thread {
public void run() {
if (mp != null) {
int currentPosition = 0;
int total = mp.getDuration();
while (currentPosition < total && mp.isPlaying() && stopSongProgressThread==false ) {
try {
Thread.sleep(500);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
songProgress.setProgress(currentPosition);
showProgress(currentPosition, total);
}
}
}
}
private void showProgress(int currentPosition, int duration) {
Bundle bundle = new Bundle();
bundle.putString("playedTime", getPlayedTime(currentPosition));
bundle.putString("remainingTime",getRemainigTime(currentPosition, duration));
Message msg = new Message();
msg.setData(bundle);
songProgresshandler.sendMessage(msg);
}
Handler songProgresshandler = new Handler() {
public void handleMessage(Message message) {
final Bundle b = message.getData();
playedTime.setText(b.getString("playedTime"));
remainingTime.setText("-" + b.getString("remainingTime"));
}
};
单击“下一步/上一步”按钮时您做了什么
可能mediaPlayer处于无效状态,请查看LogCat中的任何错误消息?(如“无效状态中的getDuration())请粘贴getPlayedTime()和getRemainingTime实现注意,可以将它们缩进四个空格。编辑器工具栏中的“{}”按钮可以为您执行此操作。编辑您的问题并进行尝试。单击编辑器工具栏中的橙色问号以获取有关格式设置的详细信息和提示。请使用请求的代码更新问题。一般来说,回应澄清的请求时,更新你的帖子,而不是回复评论。首先,一个问题不需要阅读评论就可以理解。另一方面,QA和站点,而不是论坛,评论不是有意的(也不是很适合)讨论。这样做的一个好处是,其他人可以使用,您将收到一个通知,说明有人在评论中向您发送了地址。
class SongProgressUpdateThread extends Thread {
public void run() {
if (mp != null) {
int currentPosition = 0;
int total = mp.getDuration();
while (currentPosition < total && mp.isPlaying() && stopSongProgressThread==false ) {
try {
Thread.sleep(500);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
songProgress.setProgress(currentPosition);
showProgress(currentPosition, total);
}
}
}
}
private void showProgress(int currentPosition, int duration) {
Bundle bundle = new Bundle();
bundle.putString("playedTime", getPlayedTime(currentPosition));
bundle.putString("remainingTime",getRemainigTime(currentPosition, duration));
Message msg = new Message();
msg.setData(bundle);
songProgresshandler.sendMessage(msg);
}
Handler songProgresshandler = new Handler() {
public void handleMessage(Message message) {
final Bundle b = message.getData();
playedTime.setText(b.getString("playedTime"));
remainingTime.setText("-" + b.getString("remainingTime"));
}
};