diff --git a/user_scripts/XAudioJS/XAudioServer.js b/user_scripts/XAudioJS/XAudioServer.js index 8284ac6..1ce680a 100644 --- a/user_scripts/XAudioJS/XAudioServer.js +++ b/user_scripts/XAudioJS/XAudioServer.js @@ -165,28 +165,7 @@ XAudioServer.prototype.initializeMozAudio = function () { this.initializeResampler(XAudioJSMozAudioSampleRate); } XAudioServer.prototype.initializeWebAudio = function () { - if (!XAudioJSWebAudioLaunchedContext) { - try { - XAudioJSWebAudioContextHandle = new AudioContext(); //Create a system audio context. - } - catch (error) { - XAudioJSWebAudioContextHandle = new webkitAudioContext(); //Create a system audio context. - } - XAudioJSWebAudioLaunchedContext = true; - } - if (XAudioJSWebAudioAudioNode) { - XAudioJSWebAudioAudioNode.disconnect(); - XAudioJSWebAudioAudioNode.onaudioprocess = null; - XAudioJSWebAudioAudioNode = null; - } - try { - XAudioJSWebAudioAudioNode = XAudioJSWebAudioContextHandle.createScriptProcessor(XAudioJSSamplesPerCallback, 0, XAudioJSChannelsAllocated); //Create the js event node. - } - catch (error) { - XAudioJSWebAudioAudioNode = XAudioJSWebAudioContextHandle.createJavaScriptNode(XAudioJSSamplesPerCallback, 0, XAudioJSChannelsAllocated); //Create the js event node. - } - XAudioJSWebAudioAudioNode.onaudioprocess = XAudioJSWebAudioEvent; //Connect the audio processing event to a handling function so we can manipulate output - XAudioJSWebAudioAudioNode.connect(XAudioJSWebAudioContextHandle.destination); //Send and chain the output of the audio manipulation to the system audio output. + this.setupWebAudio(); this.resetCallbackAPIAudioBuffer(XAudioJSWebAudioContextHandle.sampleRate); this.audioType = 1; /* @@ -220,9 +199,10 @@ XAudioServer.prototype.initializeWebAudio = function () { }, 500); } if (this.userEventLatch && typeof XAudioJSWebAudioContextHandle.state != "undefined") { + var parentObj = this; var lazyEnableWA = function () { if(XAudioJSWebAudioContextHandle.state === 'suspended') { - XAudioJSWebAudioContextHandle.resume(); + parentObj.setupWebAudio(); } } try { @@ -233,6 +213,31 @@ XAudioServer.prototype.initializeWebAudio = function () { catch (e) {} } } +XAudioServer.prototype.setupWebAudio = function () { + if (XAudioJSWebAudioLaunchedContext) { + XAudioJSWebAudioContextHandle.close(); + } + try { + XAudioJSWebAudioContextHandle = new AudioContext(); //Create a system audio context. + } + catch (error) { + XAudioJSWebAudioContextHandle = new webkitAudioContext(); //Create a system audio context. + } + XAudioJSWebAudioLaunchedContext = true; + if (XAudioJSWebAudioAudioNode) { + XAudioJSWebAudioAudioNode.disconnect(); + XAudioJSWebAudioAudioNode.onaudioprocess = null; + XAudioJSWebAudioAudioNode = null; + } + try { + XAudioJSWebAudioAudioNode = XAudioJSWebAudioContextHandle.createScriptProcessor(XAudioJSSamplesPerCallback, 0, XAudioJSChannelsAllocated); //Create the js event node. + } + catch (error) { + XAudioJSWebAudioAudioNode = XAudioJSWebAudioContextHandle.createJavaScriptNode(XAudioJSSamplesPerCallback, 0, XAudioJSChannelsAllocated); //Create the js event node. + } + XAudioJSWebAudioAudioNode.onaudioprocess = XAudioJSWebAudioEvent; //Connect the audio processing event to a handling function so we can manipulate output + XAudioJSWebAudioAudioNode.connect(XAudioJSWebAudioContextHandle.destination); //Send and chain the output of the audio manipulation to the system audio output. +} XAudioServer.prototype.initializeFlashAudio = function () { var existingFlashload = document.getElementById("XAudioJS"); this.flashInitialized = false;