0

I am implementing a mp3 player which is command line.

I want show the mp3 duration like this

Now Playing :: hello.mp3 Duration :: 1.20 

But when I use System.out.println it shows

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

Basically the duration getting update by a thread, I want to show it a single line, I mean the duration have to be updated in single line. I have see the Flushable interface but didn't get it. Please help me out

here is my thread

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);
}
Shantanu Banerjee
  • 1,417
  • 6
  • 31
  • 51

2 Answers2

0

It is pretty clear that something is calling println multiple times. If you don't want multiple lines, change your code so that it doesn't do that.

This is neither the "fault" of threading, or of println, and it is nothing to do with flushing. The problem is in the logic of your code ... but we can't say any more, because you haven't shown it to us.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • @ShantanuBanerjee I don't know much more about your code, but you can also make use of Timer. – Smit Dec 15 '12 at 08:55
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);
}

This is solve my problem.

Note: I don't see any effect in Eclipse Console, When I run it on CMD then its works

Shantanu Banerjee
  • 1,417
  • 6
  • 31
  • 51