title: Web Audio API: How to play a stream of MP3 chunks
body: <p>So I'm trying to use <code>Web Audio API</code> to decode &amp; play MP3 file chunks streamed to the browser using Node.js &amp; Socket.IO.</p>
  
  <p>Is my only option, in this context, to create a new <code>AudioBufferSourceNode</code> for each audio data chunk received or is it possible to create a single <code>AudioBufferSourceNode</code> for all chunks and simply append the new audio data to the end of source node's <code>buffer</code> attribute?</p>
  
  <p>Currently this is how I'm receiving my MP3 chunks, decoding them and scheduling them for playback. I have already verified that each chunk being received is a 'valid MP3 chunk' and is being successfully decoded by the Web Audio API.</p>
  
  <pre><code>audioContext = new AudioContext();
  startTime = 0;
  
  socket.on('chunk_received', function(chunk) {
      audioContext.decodeAudioData(toArrayBuffer(data.audio), function(buffer) {
          var source = audioContext.createBufferSource();
          source.buffer = buffer;
          source.connect(audioContext.destination);
  
          source.start(startTime);
          startTime += buffer.duration;
      });
  });
  </code></pre>
  
  <p>Any advice or insight into how best to 'update' Web Audio API playback with new audio data would be greatly appreciated.      </p>