我想将音频文件的播放(在某些情况下)限制为前十秒。
有没有办法结合使用 onTimeUpdate、currentTime 和暂停命令来确保播放无法处理到某个点之后。
我不想修改该文件,因为在其他情况下我需要完整的文件。
我想我想做类似的事情。
每次达到 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 命令。
知道我做错了什么吗?
最佳答案
pause()
是一个函数
function myFunction(event) {
// Trying to stop the player if it goes above 1 second
if (event.currentTime > 10) {
event.pause();
event.currentTime = 0
}
}
关于javascript - HTML5 音频 - 将播放/下载限制为前 x 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34635403/