Adding data to an already existing AudioBuffer object

I want to add data to a pre-existing AudioBuffer that is played using web audio.

After getting the audio data to play, I create an AudioBuffer and then assign the data to the ArrayBuffer in response.

    var audioBuffer = context.createBuffer(1, audioToPlay.length, 16000);


Then I create a buffer source source node and connect the audio buffer to the web audio context.

    var source = context.createBufferSource();
    source.buffer = audioBuffer;


Now what I would like to do is add more data (another ArrayBuffer) to the current playing buffer, while avoiding to use a callback onended

to create a new buffer.

Is there a way to do this? From what I can tell, this doesn't seem to be supported.


source to share

1 answer

You cannot do this. When the game buffer is passed to the AV stream via start (), it cannot be changed.

However, you said that you shouldn't use onended either. What you need to do is keep track of the last scheduled audiobook and the current time it was started, and create and play a new audio buffer at time = lastCurrentTimeStart + lastBufferDuration. You should be able to play it smoothly.



All Articles