直接上代码:
public void method3() throws Exception {
URL urlfile = new URL("http://www.greenworm.com/ising/song02/135_158.mp3");
//File file = new File("C:\\music\\test2.mp3");
//URL urlfile = file.toURI().toURL();
URLConnection con = urlfile.openConnection();
int b = con.getContentLength();// 得到音乐文件的总长度
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
Bitstream bt = new Bitstream(bis);
Header h = bt.readFrame();
int time = (int) h.total_ms(b);
System.out.println(time / 1000);
}
urlfile为网络mp3的真实链接,换成你们自己的,如果想获取本地的就需要转换一下
File file = new File("C:\\music\\test2.mp3");
URL urlfile = file.toURI().toURL();
需要借助JLayer类库实现,源码下载地址:http://download.csdn.net/detail/jys1109/5871797
本文详细介绍了如何利用JLayer类库从网络或本地获取mp3文件,并通过读取文件流来解析音乐文件的基本信息,如总长度等。重点在于提供了一段实用的代码示例,帮助开发者轻松实现mp3文件信息的获取。
1144





