Answer the question
In order to leave comments, you need to log in
Why is the buffer reset to zero after the decodeAudioData method has run?
There is the following code:
function play(arraybuffer) {
let audioCtx = new AudioContext();
let audioData = arraybuffer;
audioCtx.decodeAudioData(
audioData,
function (buffer) {
let smp = audioCtx.createBufferSource();
smp.buffer = buffer;
smp.connect(audioCtx.destination);
smp.start(0);
},
function (e) {
console.log( "Error with decoding audio data: " + e.err );
}
);
}
console.log(sound); // Выведет ArrayBuffer(106488) {}
play(sound);
console.log(sound); // Выведет ArrayBuffer(0) {}
Answer the question
In order to leave comments, you need to log in
Context creation and decoding need to be done once. Save the audio buffer to the variable buffer . But every time you start play, do only what is necessary
play () {
source = context.createBufferSource()
source.buffer = buffer
source.connect(destination)
source.start()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question