Javascript HTML5音频-将播放/下载限制在前x秒

Javascript HTML5音频-将播放/下载限制在前x秒,javascript,html,audio,html5-audio,Javascript,Html,Audio,Html5 Audio,我想将音频文件(在某些情况下)的播放限制在前十秒 有没有一种方法可以结合使用onTimeUpdate、currentTime和pause命令来确保播放不能超过某一点 我不想修改文件,因为在其他情况下,我需要完整的文件 我想我想做一些类似的事情 每次达到10时重置为0 <audio controls ontimeupdate="myFunction(this)"> <source src="horse.ogg" type="audio/ogg"> <sourc

我想将音频文件(在某些情况下)的播放限制在前十秒

有没有一种方法可以结合使用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>

函数myFunction(事件){
//如果超过1秒,试图阻止玩家
如果(event.currentTime>10){
事件暂停;
event.currentTime=0
}
}
它会适当地重置,但我无法让它关闭。它只是循环运行,忽略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
    }
}
pause()
是一个函数

function myFunction(event) {
    // Trying to stop the player if it goes above 1 second
    if (event.currentTime > 10) {
        event.pause();
        event.currentTime = 0
    }
}
你可能想看看你可能想看看