按下元素的播放按钮时如何设置媒体的开始位置?
我试图在以下事件中设置 currentTime (audio.currentTime = musicStartTime),但它们似乎都被忽略,或者导致无限的事件循环
负载
canplaythrough
玩
...或者我是否需要为此用例创建100%自定义控件UI?
使用Chrome测试,FF。
示例代码::
$(this.audio).bind("load", function() {
audio.currentTime = musicStartTime;
console.log("Loaded:" + src);
});
$(this.audio).bind("play", function() {
console.log("Trying to set start time:" + musicStartTime);
audio.currentTime = musicStartTime;
});
audio.src = src;
答案 0 :(得分:2)
尝试类似以下内容,不使用jQuery:
<audio id="myAudioElement" src="myFile.mp3" type="audio/mp3"></audio>
var audio = document.getElementById("myAudioElement");
var musicStartTime = 5;
audio.addEventListener('canplaythrough', function() {
audio.currentTime = musicStartTime;
console.log("Loaded:" + src);
}, false);