Pergunta

I've written the following piece of code

Media hit = new Media(dir); 
MediaPlayer player = new MediaPlayer(hit);
runMedia run = new runMedia(player);
Ui.changeGuiTitle("Now playing: "+getLastBitFromUrl(dirUnencoded.toString()));
Ui.updateInitialTime(getTime(hit.getDuration().toSeconds()));

getTime method:

System.out.println(time);
System.out.println(Math.round(time));
double seconds = Math.round(time);
double modulo = seconds % 60;
double hours = (seconds - modulo) / 3600;
double minutes = hours / 60;
String Time = "";

if (hours > 0.5)
{
    Time = Math.round(hours) + " : " + Math.round(minutes) + " : "  
    +   Math.round(seconds);
}
else
{
    Time = Math.round(minutes) + " : " + Math.round(seconds);
}
return Time;

It doesn't give an error, but my problem is some songs return 0 at .getDuration().toSeconds(), and other songs return their value perfectly fine. What could cause this problem?

EDIT: In debug mode a song contains 136280.816326 millis.. while System.out.println(time) returns 0

http://imgur.com/1oN0Vxk -- difference between debug and normal build

Foi útil?

Solução

I experienced Problems with this too. After Creating the Media Object it needs some time to get fully initialized (my experience).

You can tryto call your getTime-Method in MediaPlayer's onReady or onPlaying methods.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top