關於HTML5中audio音頻播放器的一些理解

來源:互聯網
上載者:User

標籤:audio   html5   audio播放器   

    最近由於工作需要音頻,瞭解到了HTML5中新興的audio音頻播放器。關於它本身的內建的屬性不過多介紹,但是需要著重提到的就是它自身就有play()和pause()兩個函數可以拿來直接使用,也就是我們經常遇到的播放和暫停功能。下面是我寫的執行個體,有興趣的朋友可以下載附件觀看。今天晚上能把這個問題搞出來,基本上HTML5中audio的一些常見,常用的需求都可以解決了。開心~650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0002.gif" alt="j_0002.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0003.gif" alt="j_0003.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0028.gif" alt="j_0028.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0019.gif" alt="j_0019.gif" />

<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>audio播放器</title><style>body{ background:#000; }/*音樂表徵圖*/#audio_btn{position: absolute;right: 10px;top: 10px;z-index: 200;display: none;width: 50px;height: 50px;background-repeat: no-repeat;/*background-repeat: no-repeat;*//*background-size: 100% 100%;*//*background-position: 0px 0px;*/}.loading_background {background-image: url(images/music_loading.gif);background-size: 30px 30px;opacity: 0.5;background-position: center center;}.loading_yinfu {position: absolute;left: 10px;top: 10px;width: 30px;height:30px;background-image: url(images/yinfu.png);background-repeat: no-repeat;background-position: center center;}.play_yinfu {background-image: url(images/music.gif);background-repeat: no-repeat;background-position: center center;background-size: 60px 60px;}.rotate {position: absolute;left: 10px;top: 10px;width: 30px;height: 30px;background-size: 100% 100%;background-image: url(images/music_off.png);-webkit-animation: rotating 1.2s linear infinite;-moz-animation: rotating 1.2s linear infinite;-o-animation: rotating 1.2s linear infinite;animation: rotating 1.2s linear infinite;}@-webkit-keyframes rotating {    from{        -webkit-transform: rotate(0deg);    }    to{        -webkit-transform: rotate(360deg);    }}@keyframes rotating {    from{        transform: rotate(0deg);    }    to{        transform: rotate(360deg);    }}@-moz-keyframes rotating {    from{        -moz-transform: rotate(0deg);    }    to{        -moz-transform: rotate(360deg);    }}/*#audio_btn.off{background-position: 0px -30px;}*/.off{background-image: url(images/music_off.png);background-size: 30px 30px; background-repeat: no-repeat;background-position: center center;}</style></head><body><div id="audio_btn" class="play_yinfu" style="display: block;">    <div id="yinfu" class="rotate"></div>    <audio loop="" src="http://res.eqxiu.com/group1/M00/C1/80/yq0KA1SBxH-AXyFZACYJPHiWsYg966.mp3" id="media" autoplay="" preload="">對不起,您的瀏覽器不支援音頻播放~</audio></div></body></html><script>window.onload = function () {var oAudioBtn = document.getElementById(‘audio_btn‘);var onOff = true;oAudioBtn.onclick = function () {if(onOff){document.getElementById(‘media‘).pause();document.getElementById(‘audio_btn‘).className = ‘off‘;document.getElementById(‘yinfu‘).className = ‘‘;onOff = false;}else{document.getElementById(‘media‘).play();document.getElementById(‘audio_btn‘).className = ‘play_yinfu‘;document.getElementById(‘yinfu‘).className = ‘rotate‘;onOff = true;}};};</script>


本文出自 “趙慶貝” 部落格,請務必保留此出處http://zhaoqingbei.blog.51cto.com/702395/1600903

關於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.