最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Appending data to an already existing AudioBuffer object - Stack Overflow

programmeradmin1浏览0评论

I'm looking to append data to an already existing AudioBuffer that is being played using web audio.


Upon receiving audio data to play, I create an AudioBuffer and then assign the data to the ArrayBuffer response.

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

I then create a buffer source node and hook up the audio buffer to the web audio context.

    var source = context.createBufferSource();
    source.buffer = audioBuffer;
    source.connect(context.destination);
    source.start(0);

Now, what I would like to do is append more data (another ArrayBuffer) to the currently playing buffer, while avoiding having to use the onended callback to create a new buffer..

Is there any way to do this? From what I can tell, this does not appear to be supported.

I'm looking to append data to an already existing AudioBuffer that is being played using web audio.


Upon receiving audio data to play, I create an AudioBuffer and then assign the data to the ArrayBuffer response.

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

I then create a buffer source node and hook up the audio buffer to the web audio context.

    var source = context.createBufferSource();
    source.buffer = audioBuffer;
    source.connect(context.destination);
    source.start(0);

Now, what I would like to do is append more data (another ArrayBuffer) to the currently playing buffer, while avoiding having to use the onended callback to create a new buffer..

Is there any way to do this? From what I can tell, this does not appear to be supported.

Share Improve this question asked Sep 26, 2014 at 21:01 Nirvana TikkuNirvana Tikku 4,2052 gold badges22 silver badges28 bronze badges 2
  • Have you looked at stackoverflow./questions/14143652/… – Rob M. Commented Sep 26, 2014 at 21:05
  • Yes - however, in this case, Im dealing with a stream (I don't have all the buffers up front) – Nirvana Tikku Commented Sep 26, 2014 at 21:06
Add a ment  | 

1 Answer 1

Reset to default 8

You cannot do this. Once a playing buffer has been handed off to the audio thread via start(), you can't modify it.

However, that said, you absolutely should not be using onended, either. What you should do is keep track of the last audiobuffer scheduled and the currentTime at which it was started, and create and play a NEW audio buffer at time = lastCurrentTimeStart+lastBufferDuration. You should be able to get a smooth, uninterrupted playback.

发布评论

评论列表(0)

  1. 暂无评论