var failureSoundBuffer = null; var successSoundBuffer = null; // Fix up prefixing window.AudioContext = window.AudioContext || window.webkitAudioContext; var context = new AudioContext(); function loadFailureSound() { var request = new XMLHttpRequest(); request.open('GET', 'failure.wav', true); request.responseType = 'arraybuffer'; // Decode asynchronously request.onload = function() { context.decodeAudioData(request.response, function(buffer) { failureSoundBuffer = buffer; }); } request.send(); } function loadSuccessSound() { var request = new XMLHttpRequest(); request.open('GET', 'success.wav', true); request.responseType = 'arraybuffer'; // Decode asynchronously request.onload = function() { context.decodeAudioData(request.response, function(buffer) { successSoundBuffer = buffer; }); } request.send(); } function playSound(theBuffer) { var source = context.createBufferSource(); // creates a sound source source.buffer = theBuffer; // tell the source which sound to play source.connect(context.destination); // connect the source to the context's destination (the speakers) source.start(0); // play the source now // note: on older systems, may have to use deprecated noteOn(time); } function playFailureSound() { playSound(failureSoundBuffer); } function playSuccessSound() { playSound(successSoundBuffer); } function jenkinsBuildPrepareAudio() { loadFailureSound(); loadSuccessSound(); } jenkinsBuildPrepareAudio();