標籤:http io color ar os java sp 檔案 資料
mp3格式播放大家都知道,amr格式就陌生了,至少我之前沒有做過
amr格式檔案播放出來的聲音音質比mp3差,主要應用於手機鈴聲和手機錄音,目的是為了給手機使用者節省流量。大部分主流的音視頻播放器都支援amr格式,現在要實現網頁播放有點問題(還要考慮相容性)。百度一番,調試一番,終於聽到聲音了。
筆者採用的播放外掛程式是QuickTime,不知道的可以百科一下,下面就是方法了:
1、下載QuickTime軟體並安裝,地址 http://www.apple.com/quicktime/download/index.html
2、在網頁添加以下代碼
//<//embed controller="true" bgcolor="black" target="myself" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/index.html" align="middle" height="10" width="1000">
3、效果,無圖無真相,進度條會動的哦
[轉載]網頁開發之amr音訊播放(後台判斷音頻長度)
IE、FireFox、chrome測試通過。
另外附上後台得到amr音訊播放長度的java代碼
public static long getAmrDuration(File file) throws IOException { long duration = -1; int[] packedSize = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; RandomAccessFile randomAccessFile = null; try { randomAccessFile = new RandomAccessFile(file, "rw"); long length = file.length();//檔案的長度 int pos = 6;//設定初始位置 int frameCount = 0;//初始幀數 int packedPos = -1; byte[] datas = new byte[1];//初始資料值 while (pos <= length) { randomAccessFile.seek(pos); if (randomAccessFile.read(datas, 0, 1) != 1) { duration = length > 0 ? ((length - 6) / 650) : 0; break; } packedPos = (datas[0] >> 3) & 0x0F; pos += packedSize[packedPos] + 1; frameCount++; } duration += frameCount * 20;//幀數*20 } finally { if (randomAccessFile != null) { randomAccessFile.close(); } } return duration; }
方法自己調用,親測可用。
網頁開發之amr音訊播放