Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / 用JavaScript操纵HTML5的本地音频

HTML5的音频元素是一个非常强大的元素并且可以避免过多依赖第三方插件。例如QuickTime,Flash。最新的浏览器,比如Chrome10+和Firefox3.6+都已经嵌入了JavaScript库,并且还提供了方法和属性来操纵<audio>元素。在这篇文章中,我们将探讨几种最重要的方法并探讨如何使用JavaScript来运行audio文件。摘要:尽管这篇文章主要介绍Audio对象,但是这些方法和属性也同样适用于Video对象。Audio Methods.load();---Loads and re-loads the audio element for playback。(加载或者重加载audio元素实现重播)
  1. audioElement.load();    
.play();---Starts playing the audio file。(开始播放音频文件)
  1. audioElement.play();   
.pause();Pauses playback of the audio file。(暂停播放音频文件)
  1. audioElement.pause();   
canPlayType(type);---Checks with browser to see if type of audio file is supported。(检查浏览器是否支持音频文件)
  1. audioElement.canPlayType("audio/ogg; codecs="vorbis"");   
Audio Properties.currentTime---Sets or returns the playback position in the audio file, Value is in seconds。(设置或返回音频文件开始播放的位置,返回值以“秒”为单位) 
  1. audioElement.currentTime = seconds; 
.duration---Returns the length of the audio file in seconds。(返回播放音频在某秒上的播放的长度) 
  1. var seconds = audioElement.duration; 
.src---The url where the audio file exists。(音频文件的url) 
  1. audioElement.src = "audio.ogg"; 
.volume---Sets or returns the volume of the audio file。(设置或返回音频文件的体积) 
  1. audioElement.volume = value; 
注意:以上并没有把音频的所有方法和属性列出来,只介绍了常用的几个方法和属性。