I got this snippet from a website (can't remember where at the moment) and it has stopped working.
I use it to play a tone.
Is it something that I'm doing wrong or has Chrome changed recently?
Play = (function () {
var ctx = new(window.audioContext || window.webkitAudioContext);
return function (duration, freq, finishedCallback) {
duration = +duration;
if (typeof finishedCallback != "function") {
finishedCallback = function () {};
}
var osc = ctx.createOscillator();
osc.type = 0;
osc.connect(ctx.destination);
osc.frequency.value = freq;
osc.noteOn(0);
setTimeout(
function () {
osc.noteOff(0);
finishedCallback();
}
,duration
);
};
})();
Play(50,500)