網頁開發之amr音訊播放

來源:互聯網
上載者:User

標籤: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音訊播放

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.