|
@@ -67141,8 +67141,10 @@ var BABYLON;
|
|
|
*
|
|
|
* There should be only one per page as some browsers restrict the number
|
|
|
* of audio contexts you can create.
|
|
|
+ * @param engine defines the hosting engine
|
|
|
*/
|
|
|
- function AudioEngine() {
|
|
|
+ function AudioEngine(engine) {
|
|
|
+ if (engine === void 0) { engine = BABYLON.Engine.LastCreatedEngine; }
|
|
|
var _this = this;
|
|
|
this._audioContext = null;
|
|
|
this._audioContextInitialized = false;
|
|
@@ -67156,7 +67158,6 @@ var BABYLON;
|
|
|
* @ignoreNaming
|
|
|
*/
|
|
|
this.WarnedWebAudioUnsupported = false;
|
|
|
- this.unlocked = false;
|
|
|
/**
|
|
|
* Gets whether or not mp3 are supported by your browser.
|
|
|
*/
|
|
@@ -67171,8 +67172,10 @@ var BABYLON;
|
|
|
* a user interaction has happened.
|
|
|
*/
|
|
|
this.unlocked = false;
|
|
|
- this._audioContext = null;
|
|
|
- this._audioContextInitialized = false;
|
|
|
+ /**
|
|
|
+ * Event raised when audio has been unlocked on the browser.
|
|
|
+ */
|
|
|
+ this.onAudioUnlockedObservable = new BABYLON.Observable();
|
|
|
this._onResize = function () {
|
|
|
_this._moveButtonToTopLeft();
|
|
|
};
|
|
@@ -67181,6 +67184,7 @@ var BABYLON;
|
|
|
this.canUseWebAudio = true;
|
|
|
}
|
|
|
var audioElem = document.createElement('audio');
|
|
|
+ this._engine = engine;
|
|
|
try {
|
|
|
if (audioElem && !!audioElem.canPlayType && audioElem.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/, '')) {
|
|
|
this.isMP3supported = true;
|
|
@@ -67197,8 +67201,6 @@ var BABYLON;
|
|
|
catch (e) {
|
|
|
// protect error during capability check.
|
|
|
}
|
|
|
- this._canvas = BABYLON.Engine.LastCreatedEngine.getRenderingCanvas();
|
|
|
- window.addEventListener("resize", this._onResize);
|
|
|
if (/iPad|iPhone|iPod/.test(navigator.platform)) {
|
|
|
this._unlockiOSaudio();
|
|
|
}
|
|
@@ -67285,9 +67287,7 @@ var BABYLON;
|
|
|
this._hideMuteButton();
|
|
|
}
|
|
|
// Notify users that the audio stack is unlocked/unmuted
|
|
|
- if (this.onAudioUnlocked) {
|
|
|
- this.onAudioUnlocked();
|
|
|
- }
|
|
|
+ this.onAudioUnlockedObservable.notifyObservers(this);
|
|
|
};
|
|
|
AudioEngine.prototype._triggerSuspendedState = function () {
|
|
|
this.unlocked = false;
|
|
@@ -67310,9 +67310,11 @@ var BABYLON;
|
|
|
this._muteButton.addEventListener('mousedown', function () { _this._resumeAudioContext(); }, false);
|
|
|
}
|
|
|
this._muteButtonDisplayed = true;
|
|
|
+ this._canvas = this._engine.getRenderingCanvas();
|
|
|
+ window.addEventListener("resize", this._onResize);
|
|
|
};
|
|
|
AudioEngine.prototype._moveButtonToTopLeft = function () {
|
|
|
- if (this._canvas) {
|
|
|
+ if (this._canvas && this._muteButton) {
|
|
|
this._muteButton.style.top = this._canvas.offsetTop + 20 + "px";
|
|
|
this._muteButton.style.left = this._canvas.offsetLeft + 20 + "px";
|
|
|
}
|
|
@@ -67340,6 +67342,7 @@ var BABYLON;
|
|
|
this.WarnedWebAudioUnsupported = false;
|
|
|
this._hideMuteButton();
|
|
|
window.removeEventListener("resize", this._onResize);
|
|
|
+ this.onAudioUnlockedObservable.clear();
|
|
|
};
|
|
|
/**
|
|
|
* Gets the global volume sets on the master gain.
|
|
@@ -67923,7 +67926,7 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- window.setTimeout(tryToPlay, 500);
|
|
|
+ BABYLON.Engine.audioEngine.onAudioUnlockedObservable.addOnce(function () { return tryToPlay; });
|
|
|
}
|
|
|
};
|
|
|
tryToPlay();
|