|
@@ -1,26 +1,52 @@
|
|
|
package cn.efunbox.audio.utils;
|
|
|
|
|
|
+import javazoom.jl.decoder.Bitstream;
|
|
|
import javazoom.jl.decoder.BitstreamException;
|
|
|
+import javazoom.jl.decoder.Header;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import ws.schild.jave.Encoder;
|
|
|
import ws.schild.jave.MultimediaInfo;
|
|
|
import ws.schild.jave.MultimediaObject;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.nio.channels.FileChannel;
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
|
|
@Slf4j
|
|
|
public class Test {
|
|
|
public static void main(String[] args) throws IOException, BitstreamException {
|
|
|
|
|
|
|
|
|
-// getFileList("H:\\7m");
|
|
|
+ URL urlfile;
|
|
|
+ URLConnection con;
|
|
|
+ try {
|
|
|
+ urlfile = new URL("http://asxx-video.ai160.com/vs2m-mp4/BD052/BD05203/BD05203.mp4");
|
|
|
+ con = urlfile.openConnection();
|
|
|
+ int b = con.getContentLength();// 得到音乐文件的总长度
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
|
|
+ Bitstream bt = new Bitstream(bis);
|
|
|
+ Header h = bt.readFrame();
|
|
|
+ double time = h.total_ms(b);
|
|
|
+ System.out.println("文件时长为" +time / (1000 * 60));
|
|
|
+ int fileLength = con.getContentLength();
|
|
|
+ if (fileLength <= 0)
|
|
|
+ System.out.println("无法获知文件大小");
|
|
|
+ // 打印信息
|
|
|
+ DecimalFormat df = new DecimalFormat("0.0");// 格式化小数
|
|
|
+ String num = df.format((float) fileLength / (1024 * 1024));
|
|
|
+ System.out.println("文件大小为" + num + "M");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //secondToTime(getMicrosecondLength("http://asxx-video.ai160.com/vs2m-mp4/BD052/BD05201/BD05201.mp4"));
|
|
|
|
|
|
- File source = new File("http://baidu-yuwen-video.ai160.com/vs2m/001/00103052/00103052001/00103052001.m3u8");
|
|
|
+// getFileList("H:\\7m");
|
|
|
+ /*
|
|
|
+ File source = new File("http://asxx-video.ai160.com/vs2m-mp4/BD052/BD05201/BD05201.mp4");
|
|
|
|
|
|
String strFileName = source.getName();
|
|
|
String readVideoTime = ReadVideoTime(source);
|
|
@@ -28,7 +54,7 @@ public class Test {
|
|
|
|
|
|
log.info("title : {} ,time : {},size : {}",strFileName,readVideoTime,s);
|
|
|
|
|
|
-
|
|
|
+ */
|
|
|
|
|
|
/* URL urlfile = new URL("http://ai-admin-audio.ai160.com/audio/001/00103035/00103035019.mp3");
|
|
|
URLConnection con = null;
|
|
@@ -129,4 +155,60 @@ public class Test {
|
|
|
}
|
|
|
return size;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取音频文件时长
|
|
|
+ *
|
|
|
+ * @param filePath wav文件路径,支持本地和网络HTTP路径
|
|
|
+ * @return 时长/毫秒,可 /1000D 得到秒
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static long getMicrosecondLength(String filePath) {
|
|
|
+
|
|
|
+ long countTime = 0;
|
|
|
+ try {
|
|
|
+ URL urlfile = new URL(filePath);
|
|
|
+ //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);
|
|
|
+ countTime = time/1000;
|
|
|
+ } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+ log.error("get time is error! url : {}" ,filePath);
|
|
|
+ } finally {
|
|
|
+ return countTime;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回日时分秒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static void secondToTime(long seconds) {
|
|
|
+ MultimediaInfo info = null;
|
|
|
+
|
|
|
+ String trackLength = "";
|
|
|
+
|
|
|
+
|
|
|
+ long temp=0;
|
|
|
+ StringBuffer sb=new StringBuffer();
|
|
|
+ temp = seconds/3600;
|
|
|
+ sb.append((temp<10)?"0"+temp+":":""+temp+":");
|
|
|
+
|
|
|
+ temp=(seconds%3600)/60;
|
|
|
+ sb.append((temp<10)?"0"+temp+":":""+temp+":");
|
|
|
+
|
|
|
+ temp=(seconds%3600)%60;
|
|
|
+ sb.append((temp<10)?"0"+temp:""+temp);
|
|
|
+
|
|
|
+ System.out.println(sb.toString());
|
|
|
+ }
|
|
|
}
|