我已经编写了以下代码
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方法:
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;
没有报错,但我的问题是有些歌曲在 .getDuration().toSeconds()
返回 0
,而其他歌曲则正常返回其值。这个问题可能是由什么引起的?
编辑:
在调试模式下,一首歌曲包含 136280.816326
毫秒...而 System.out.println(time)
返回 0
http://imgur.com/1oN0Vxk -- 调试版和正常编译版之间的差异
Media
类来自哪个库? - Stewart