1
2 com.badlogicgames.jlayer
3 jlayer
4 1.0.2-gdx
5
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.Header;
public static void main(String[] args) {
try {
long startTime=System.currentTimeMillis(); //获取开始时间
URL urlfile = new URL("http://resource.puxinwangxiao.com/b4ef18fe62948ab2528127c8c1357ddd.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);
long endTime1=System.currentTimeMillis(); //获取结束时间
System.out.println("所需时间: "+(endTime1-startTime)+"ms");
}catch (Exception e ){
System.out.println(e.getMessage());
}
}
经测试,此方法耗时少,但计算的时长有偏差:
1439s 。计算出来是 1479s
490s。计算出来是491s