如何在HTML5音频元素中跳转到某些时间偏移?
他们说你可以简单地设置他们的currentTime财产(强调我的):
currentTime获取时,该属性必须返回当前播放位置,以秒为单位表示.在设置时,如果媒体元素具有当前媒体控制器,则它必须抛出INVALID_STATE_ERR异常; 否则,用户代理必须寻找新值(这可能引发异常).
唉,它似乎不起作用(我需要在Chrome中).
有类似的问题,但没有答案.
我有一个音频文件列表,显示为链接和一个<audio>html5播放器.每个链接调用一个函数,该函数在以下内容中更改<source>标记的src <audio>:
<audio controls="controls" preload="none">
<source type="audio/mpeg" src="{{selectedSongPath}}"/>
</audio>
Run Code Online (Sandbox Code Playgroud)
...
<div class="songEntry" ng-repeat="song in songs">
<a href="" ng-click="songSelect(song.path)">{{song.name}}</a>
</div>
Run Code Online (Sandbox Code Playgroud)
...
$scope.songSelect = function(songPath) {
$scope.selectedSongPath = songPath;
}
Run Code Online (Sandbox Code Playgroud)
我可以看到src正在改变,但没有播放.路径还可以; 如果我用其中一条路径初始化src,则播放器可以工作.
我究竟做错了什么?
编辑:我在Wordpress方面发布了这个,但有些管理员认为它在这里是因为他们说这是客户端问题,但我不认为这是因为他的脚本工作原样(在非wordpress网站)但只抛出在Wordpress站点上仅在某些浏览器上使用脚本时出现DOM异常11错误.相同的脚本在Wordpress下运行,但仅在Chrome上运行.
当锚链接悬停并将其转换为Wordpress插件时,我已经采用了播放音频剪辑的脚本.
它工作正常,但仅适用于Chrome(Mac).在Firefox或Safari(当前版本)上,脚本会抛出DOM错误.
这是错误:
INVALID_STATE_ERR:DOM异常11:尝试使用不可用或不再可用的对象.
产生错误的行是: html5audio.currentTime=0
以下脚本适用于我在非Wordpress网站上遇到问题的浏览器.http://www.javascriptkit.com/script/script2/soundlink.shtml#current
我已经尝试过研究这个问题并使用一些修复但我无法开始工作.
var html5_audiotypes={
"mp3": "audio/mpeg",
"mp4": "audio/mp4",
"ogg": "audio/ogg",
"wav": "audio/wav"
}
function audio(sound){
var html5audio=document.createElement('audio')
if (html5audio.canPlayType){ //check support for HTML5 audio
for (var i=0; i<arguments.length; i++){
var sourceel=document.createElement('source')
sourceel.setAttribute('src', arguments[i])
if (arguments[i].match(/\.(\w+)$/i))
sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
html5audio.appendChild(sourceel)
}
html5audio.load()
html5audio.playclip=function(){
html5audio.pause()
html5audio.currentTime=0
html5audio.play()
}
return html5audio
}
}
Run Code Online (Sandbox Code Playgroud)