我写了以下代码
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()));
获取时间方法:
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;
它没有给出错误,但我的问题是一些歌曲返回0
,.getDuration().toSeconds()
而其他歌曲返回它们的值非常好。什么可能导致这个问题?
编辑:
在调试模式下,歌曲包含136280.816326
毫秒 .. 而System.out.println(time)
返回 0
http://imgur.com/1oN0Vxk -- 调试和正常构建的区别