日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取音视频的时长

發布時間:2024/1/8 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取音视频的时长 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

引入:jave-1.0.2.jar? 自行百度如何放到maven私服中,或者自己的倉庫中。

@Testpublic void getMp3Duration() throws EncoderException {File source =new File("c:\\吳晴-過去成向往(原版).mpg");Encoder encoder = new Encoder();MultimediaInfo m = encoder.getInfo(source);long ls = m.getDuration();System.out.println("此視頻時長為:"+ls/60000+"分"+(ls/1000-ls/60000*60)+"秒!");System.out.println("此視頻時長為:"+ls/1000+"秒!");} @Testpublic void getDuration() throws EncoderException, IOException {String url = "http://static.mifanxing.com/yyren/image/week/20171110/1/Snare-1_2inchabove.mp3";String ext = url.substring(url.lastIndexOf("."));InputStream inputStream = getImgFromUrl(url);//保存成FileFile source = inputStreamToFile(inputStream, ext);Encoder encoder = new Encoder();MultimediaInfo m = encoder.getInfo(source);long ls = m.getDuration();System.out.println("此視頻時長為:" + ls / 60000 + "分" + (ls / 1000 - ls / 60000 * 60) + "秒!");System.out.println("此視頻時長為:" + ls / 1000 + "秒!");}private InputStream getImgFromUrl(String url) throws IOException {URL myUrl = new URL(url);HttpURLConnection con = (HttpURLConnection) myUrl.openConnection();con.setConnectTimeout(5 * 1000); // InputStream is = con.getInputStream();return con.getInputStream();}private File inputStreamToFile(InputStream ins, String ext) throws IOException {String source = "";if (System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS")) {File[] roots = File.listRoots();if (roots.length > 0) {source=roots[0].toString().replaceAll("\\\\","/")+"temp/";}} else {source="/tmp/temp/";}File f = new File(source);if (!f.exists()){f.mkdir();}File file = File.createTempFile("temp", ext, f);OutputStream os = new FileOutputStream(file);int bytesRead = 0;byte[] buffer = new byte[8192];while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {os.write(buffer, 0, bytesRead);}os.close();ins.close();return file;}

?

總結

以上是生活随笔為你收集整理的获取音视频的时长的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。