Java 怎样获取Mp3文件的播放时长?
player=Manager.createPlayer(file.toURL());player.start();System.out.println(player.ge...
player = Manager.createPlayer(file.toURL()); player.start(); System.out.println(player.getDuration().getSeconds());这样为什么获取不到啊?
展开
1个回答
2013-09-21
展开全部
File file = new File("G:\\8.mp3");
long total = 0;
try {
AudioFileFormat aff = AudioSystem.getAudioFileFormat(file);
Map props = aff.properties();
if (props.containsKey("duration"))
total = (long) Math.round((((Long) props.get("duration"))
.longValue())/1000);
System.out.println(total);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long total = 0;
try {
AudioFileFormat aff = AudioSystem.getAudioFileFormat(file);
Map props = aff.properties();
if (props.containsKey("duration"))
total = (long) Math.round((((Long) props.get("duration"))
.longValue())/1000);
System.out.println(total);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询