14

我应该能够使用相同AudioBufferSourceNode的声音多次播放吗?出于某种原因,第二次调用noteGrainOn不会播放音频,即使有noteOff.

此代码仅播放一次声音:

var node = audioContext.createBufferSource()
node.buffer = audioBuffer
node.connect(audioContext.destination)

var now = audioContext.currentTime
node.noteGrainOn(now, 0, 2)
node.noteOff(now + 2)
node.noteGrainOn(now + 3, 0, 2)
node.noteOff(now + 5)
4

2 回答 2

22

一旦你回放了一个源节点,你就不能再使用它了。您需要AudioBufferSourceNode使用相同的缓冲区创建另一个。查看网络音频常见问题以了解更多信息(请参阅 noteOn() 问题)。

于 2012-02-24T23:59:07.980 回答
2

我有一些技巧可以轻松切换播放/暂停:) 您可以直接将音频映射到现有音频标签并使用其上的控件

<audio id="sound" src="./test.mp3" controls="controls"></audio>

var audioElement = document.getElementById('sound');
source = audioContext.createMediaElementSource(audioElement);
/* ... */
audioElement.pause();

我在这里运行的示例:http : //www.b2bweb.fr/bonus/Braincer/ 我目前使用 Chrome build 18.0.xxxx

其他参考:

于 2012-03-23T17:26:06.727 回答