Load and playback an audio sample from a .wav file
let m = maximilian();
/**
* maxiAudio.init() initialises the Audio Context and should execute in a button click event handler to prevent the console warning
* "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu"
*/
let playAudio = () => {
let myOsc = new m.maxiOsc();
let maxiAudio = new m.maxiAudio();
var samplePlayer = new m.maxiSample();
maxiAudio.init();
maxiAudio.loadSample("audio/beat2.wav", samplePlayer);
maxiAudio.play = function () {
if( samplePlayer.isReady() ){
return samplePlayer.play();
}
}
}
const playButton = document.getElementById('playButton');
playButton.addEventListener("click", () => playAudio());