Audio Element
Open the developer tool to view console logs.
直接奉上示例代码,废话就不多说了。
复制代码代码如下:
HTML5 Audio API demo by http://github.com/LearnShare" target="_blank">LearnShare.
Last update @2013-04-23 20:40:00 + add info table update @2013-04-22 14:54:00 + add DOM events update @2013-04-22 12:47:00 + add getCurrentSrc button
View code on http://github.com/LearnShare/LearnShare.github.io/tree/master/labs/audio/" target="_blank">LearnShare.github.io. API reference: https://developer.mozilla.org/zh-CN/docs/DOM/HTMLMediaElement" target="_blank">HTMLMediaElement and http://w3schools.com/tags/ref_av_dom.asp" target="_blank">Audio/Video DOM References
Open the developer tool to view console logs.
audio-controls.js
复制代码代码如下:
window.onload=function(){ // get autio element var audio=document.getElementById("audio"); // play() document.getElementById("play").onclick=function(){ audio.play(); console.log("play"); }; // pause() document.getElementById("pause").onclick=function(){ audio.pause(); console.log("pause"); }; // get paused document.getElementById("get_paused").onclick=function(){ console.log("audio.paused: "+audio.paused); }; // get ended document.getElementById("get_ended").onclick=function(){ console.log("audio.ended: "+audio.ended); }; // set volume- document.getElementById("volume_down").onclick=function(){ audio.volume-=0.2; console.log("volume-0.2"); }; // set volume+ document.getElementById("volume_up").onclick=function(){ audio.volume+=0.2; console.log("volume+0.2"); }; // get volume document.getElementById("get_volume").onclick=function(){ console.log("audio.volume: "+audio.volume); }; // get src document.getElementById("get_src").onclick=function(){ console.log("audio.src: "+audio.src); }; // set src_music1 document.getElementById("play_music1").onclick=function(){ audio.src="./media/music1.mp3"; updateSrc(); updateCurrentSrc(); console.log("play music1"); }; // set src_music2 document.getElementById("play_music2").onclick=function(){ audio.src="./media/music2.mp3"; updateSrc(); updateCurrentSrc(); console.log("play music2"); }; // set remove_music document.getElementById("remove_music").onclick=function(){ audio.src=""; console.log("remove music"); }; // get currentSrc document.getElementById("get_current_src").onclick=function(){ console.log("audio.currentSrc: "+audio.currentSrc); }; // get initialTime document.getElementById("get_initial_time").onclick=function(){ console.log("audio.initialTime: "+audio.initialTime); }; // get duration document.getElementById("get_duration").onclick=function(){ console.log("audio.duration: "+audio.duration); }; // get seeking document.getElementById("get_seeking").onclick=function(){ console.log("audio.seeking: "+audio.seeking); }; // set currentTime document.getElementById("jump_to").onclick=function(){ audio.currentTime=30; console.log("jumpTo 30s"); }; // get currentTime document.getElementById("get_current_time").onclick=function(){ console.log("audio.currentTime: "+audio.currentTime); }; // get played document.getElementById("get_played").onclick=function(){ console.log("audio.played:"); var ranges=audio.played; var n=ranges.length; for(var i=0;i
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~