HTML5音频-Limit播放/下载到前x秒

时间:2016-01-06 14:21:34

标签: javascript html5 audio html5-audio

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

是否可以使用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命令。

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:3)

pause()是一个函数

function myFunction(event) {
    // Trying to stop the player if it goes above 1 second
    if (event.currentTime > 10) {
        event.pause();
        event.currentTime = 0
    }
}
相关问题