为什么我的声音复卷? [英] Why isn't my audio rewinding?
问题描述
我有一个有点麻烦,在Javascript复卷音频。我基本上有蜂鸣每一秒,因为它朝倒计时结束得到了倒计时。
I'm having a bit of trouble rewinding audio in Javascript. I basically have a countdown that beeps each second as it gets towards the end of the countdown.
我试着用;
var bip = new Audio("http://www.soundjay.com/button/beep-7.wav");
bip.play();
但它没有哔每一秒,我猜有事可做withit无需加载新的声音每一秒。然后,我尝试从外部加载声音,并与下面code触发它。
but it didn't beep every second which I'm guessing has something to do withit having to load a new sound every second. I then tried loading the sound externally and triggering it with the following code.
bip.pause();
bip.currentTime = 0;
console.log(bip.currentTime);
bip.play();
但这只是播放的声音再一次完全不能倒带(这是由控制台登录0.19秒的时间第一次通关后显示)。
but this only plays the sound once then completely fails to rewind it (this is shown by the console logging a time of 0.19 seconds after the first playthrough).
有我丢失的东西在这里?
Is there something I'm missing here?
推荐答案
在谷歌浏览器,我注意到它只有当你有在同一个域中的音频文件的工作。我没有问题,如果音频文件是在同一个域中。事件设置 .currentTime
和
In google chrome I noticed that it only works if you have the audio file in same domain. I have no problems if the audio file is in same domain. Event setting .currentTime
works.
跨域:
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
我试着在Google上搜寻了一会儿,能找到什么在这个甚至任何讨论规格。
I tried googling for a while and could find nothing in specs about this or even any discussion.
这篇关于为什么我的声音复卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!