Search code examples
concatenationhtml5-audioweb-audio-apiarraybuffer

Call to AudioBufferSourceNode.start() not playing sound


What the code in my fiddle tries to do is

  • Play a "header" sound

  • Subsequently play the body/main content sound which should have a background track supporting it

  • Lastly, play an outro/footer sound

My needs are slightly similar to this thread Mixing two audio buffers, put one on background of another by using web Audio Api with minor differences here and there although I don't understand all the promises in that thread. However, I believe my code is held back by a tiny oversight. So far, I'm unable to test which of the outlined steps are successful because calls to AudioBufferSourceNode.start() do not initiate play behavior in the speakers.

Also I inspected what data is in the processed or resulting ArrayBuffers. It appears at every point/index, the array holds 0 (which probably means it's full of white noise but should play anyway). You might observe I'm using OfflineAudioContext instances at times. I intend to pipe the ultimate buffer to a library that would export it to MP3 format.

The code can be found at this fiddle. You can use any locally hosted audio files at your convenience


Solution

  • First of all, you can't call createMediaElementSource on an OfflineAudioContext; you have to use an AudioContext. Second, you probably should only create and use one AudioContext.