【问题标题】:HTML5 Audio -Limit playback/download to first x secondsHTML5 音频 - 将播放/下载限制为前 x 秒
【发布时间】: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


【解决方案1】:

pause() 是一个函数

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-27
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多