用JavaScript操纵HTML5的本地音频

2014-11-24 12:25:50 · 作者: · 浏览: 2

HTML5的音频元素是一个非常强大的元素并且可以避免过多依赖第三方插件。例如QuickTime,Flash。最新的浏览器,比如Chrome10+和Firefox3.6+都已经嵌入了java script库,并且还提供了方法和属性来操纵


摘要:尽管这篇文章主要介绍Audio对象,但是这些方法和属性也同样适用于Video对象。


Audio Methods


.load();


---Loads and re-loads the audio element for playback。(加载或者重加载audio元素实现重播)


.play();


---Starts playing the audio file。(开始播放音频文件)


.pause();


Pauses playback of the audio file。(暂停播放音频文件)


canPlayType(type);


---Checks with browser to see if type of audio file is supported。(检查浏览器是否支持音频文件)


Audio Properties


.currentTime


---Sets or returns the playback position in the audio file, Value is in seconds。(设置或返回音频文件开始播放的位置,返回值以“秒”为单位)



.duration


---Returns the length of the audio file in seconds。(返回播放音频在某秒上的播放的长度)



.src


---The url where the audio file exists。(音频文件的url)



.volume


---Sets or returns the volume of the audio file。(设置或返回音频文件的体积)



注意:以上并没有把音频的所有方法和属性列出来,只介绍了常用的几个方法和属性。