HTML5 音频 - 限制 playback/download 到前 x 秒
HTML5 Audio -Limit playback/download to first x seconds
我想将音频文件的播放限制在前十秒(在某些情况下)。
有没有办法结合使用 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 命令。
知道我做错了什么吗?
pause()
是函数
function myFunction(event) {
// Trying to stop the player if it goes above 1 second
if (event.currentTime > 10) {
event.pause();
event.currentTime = 0
}
}
我想将音频文件的播放限制在前十秒(在某些情况下)。
有没有办法结合使用 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 命令。
知道我做错了什么吗?
pause()
是函数
function myFunction(event) {
// Trying to stop the player if it goes above 1 second
if (event.currentTime > 10) {
event.pause();
event.currentTime = 0
}
}