HTML5 音頻 <audio>

來源:互聯網
上載者:User

標籤:

HTML5 提供了播放音訊標準。

一、Web 上的音頻

直到現在,仍然不存在一項旨在網頁上播放音訊標準。

今天,大多數音頻是通過外掛程式(比如 Flash)來播放的。然而,並非所有瀏覽器都擁有同樣的外掛程式。

HTML5 規定了一種通過 audio 元素來包含音訊標準方法。

audio 元素能夠播放音效檔或者音頻流。

二、使用audio標籤

<audio src="song.ogg" controls="controls"></audio>

control 屬性供添加播放、暫停和音量控制項。

<audio> 與 </audio> 之間插入的內容是供不支援 audio 元素的瀏覽器顯示的:

<!DOCTYPE html><html>    <head>        <meta charset="utf-8" />        <title></title>    </head>    <body>        <div style="text-align:center;">            <video id="video1" width="420" style="margin-top:55px;">                <source src="img/mov_bbb.mp4" type="video/mp4" />                <source src="img/mov_bbb.ogg" type="video/ogg" /> Your browser does not support HTML5 video.            </video>            <br />            <button onclick="playPause()">播放/暫停</button>            <button onclick="makeBig()">大</button>            <button onclick="makeNormal()">中</button>            <button onclick="makeSmall()">小</button>            <br/>            <br/>            <audio controls="controls">                <source src="img/qiuyinong.mp3" type="audio/mpeg">                Your browser does not support the audio tag.            </audio>        </div>        <script type="text/javascript">            var myVideo = document.getElementById("video1");            function playPause() {                if(myVideo.paused)                    myVideo.play();                else                    myVideo.pause();            }            function makeBig() {                myVideo.width = 560;            }            function makeSmall() {                myVideo.width = 320;            }            function makeNormal() {                myVideo.width = 420;            }        </script>    </body></html>

檔案夾內容

 

1、chrome瀏覽器下:

2、IE9瀏覽器下:

 

3、IE8瀏覽器下測試:

 

HTML5 音頻 <audio>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.