Web Audio API: noteOn after noteOff not working?
-
18-06-2021 - |
Вопрос
I wrote a simple web app using the Web Audio API, but I've noticed that when I issue a noteOn(0)
command to a given source, followed by a noteOff(0)
, and then finally by another noteOn(0)
command, the sound will turn on, turn off (as expected) but then won't turn on with the third command.
Is there something that I'm doing wrong? It's as simple as that, I can show you code but I feel it's redundant. Perhaps I need to reassign the buffer to the source after the noteOff
, but I can't imagine that's how it was intended to be used.
Решение
AudioBufferSourceNode can only be played once.
Другие советы
Reading here: http://www.html5rocks.com/en/tutorials/webaudio/intro/, and specifically here: http://www.html5rocks.com/en/tutorials/webaudio/intro/js/volume-sample.js, it looks like resetting the source/buffer after noteOff is the way to go. I switched that up and things are working great.
Working example code using .disconnect() with oscillator
http://en.wikiaudio.org/Web_Audio_API:Toggle_oscillator_on_and_off