0

我正在实现一个命令行 mp3 播放器。

我想像这样显示 mp3 持续时间

Now Playing :: hello.mp3 Duration :: 1.20 

但是当我使用 System.out.println 它显示

Now Playing :: hello.mp3 Duration :: 1.20 
Now Playing :: hello.mp3 Duration :: 1.21 
Now Playing :: hello.mp3 Duration :: 1.22 
Now Playing :: hello.mp3 Duration :: 1.23 
Now Playing :: hello.mp3 Duration :: 1.24 
Now Playing :: hello.mp3 Duration :: 1.25
..... 

基本上通过线程获取更新的持续时间,我想在一行中显示它,我的意思是持续时间必须在单行中更新。我看过Flushable interface但没看懂。请帮帮我

这是我的线程

while(p.getPlayer().isComplete() == false){
String bOutput = "\r Duration ::" + (int) ((p.getPlayer().getPosition() / (1000*60)) % 60) + " : " + (int) (p.getPlayer().getPosition() / 1000) % 60;
//p.getBufferedOutputStream().write(bOutput.getBytes());
//p.getBufferedOutputStream().flush();
System.out.println(bOutput);

Thread.sleep(1000);
}
4

2 回答 2

0

很明显,某事正在println多次调用。如果您不想要多行,请更改您的代码,使其不这样做。

这既不是线程的“错误”,也不是 的println,与刷新无关。问题在于您的代码逻辑......但我们不能再说什么,因为您还没有向我们展示它。

于 2012-12-15T08:24:00.900 回答
0
while(p.getPlayer().isComplete() == false){
String bOutput = "Duration ::" + (int) ((p.getPlayer().getPosition() / (1000*60)) % 60) + " : " + (int) (p.getPlayer().getPosition() / 1000) % 60;
System.out.println(bOutput+"\r");

Thread.sleep(1000);
}

这是解决我的问题。

注意:我没有看到任何效果Eclipse Console,当我运行它时CMD它的工作原理

于 2012-12-15T09:11:01.487 回答