【发布时间】:2016-01-06 14:21:34
【问题描述】:
我想将音频文件的播放(在某些情况下)限制在前十秒内。
有没有一种方法可以结合使用 onTimeUpdate、currentTime 和 pause 命令来确保播放不能超过某个时间点。
我不想修改文件,因为在其他情况下我需要完整的文件。
我想我想做类似的事情。
每次达到 10 时重置为 0。
<audio controls ontimeupdate="myFunction(this)">
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
</audio>
<script>
function myFunction(event) {
// Trying to stop the player if it goes above 1 second
if (event.currentTime > 10) {
event.pause;
event.currentTime = 0
}
}
</script>
它会适当地重置,但我无法让它闭嘴。它只是循环,忽略 event.pause 命令。
任何想法我做错了什么?
【问题讨论】:
标签: javascript html audio html5-audio