我在使用 Javascript 倒带音频时遇到了一些问题。我基本上有一个倒计时,当它接近倒计时结束时每秒都会发出哔哔声。
我试过使用;
var bip = new Audio("http://www.soundjay.com/button/beep-7.wav");
bip.play();
但它并没有每秒都发出哔哔声,我猜这与它必须每秒加载一个新声音有关。然后我尝试从外部加载声音并使用以下代码触发它。
bip.pause();
bip.currentTime = 0;
console.log(bip.currentTime);
bip.play();
但这只播放一次声音然后完全无法倒回它(这由控制台在第一次播放后记录 0.19 秒的时间显示)。
我在这里遗漏了什么吗?
最佳答案
在 google chrome 中,我注意到它仅在您在同一域中拥有音频文件时才有效。如果音频文件在同一个域中,我没有问题。事件设置 .currentTime
有效。
跨域:
var bip = new Audio("http://www.soundjay.com/button/beep-7.wav");
bip.play();
bip.currentTime; //0.10950099676847458
bip.currentTime = 0;
bip.currentTime; //0.10950099676847458
同域:
var bip = new Audio("beep-7.wav");
bip.play();
bip.currentTime; //0.10950099676847458
bip.currentTime = 0;
bip.currentTime; //0
我尝试谷歌搜索了一段时间,但在规范中找不到任何关于此的内容,甚至找不到任何讨论。
关于javascript - 为什么我的音频没有倒带?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11004437/