|
@@ -12576,7 +12576,7 @@ var BABYLON;
|
|
|
}
|
|
|
// Create Audio Engine if needed.
|
|
|
if (!Engine.audioEngine && options.audioEngine && Engine.AudioEngineFactory) {
|
|
|
- Engine.audioEngine = Engine.AudioEngineFactory(this);
|
|
|
+ Engine.audioEngine = Engine.AudioEngineFactory(this.getRenderingCanvas());
|
|
|
}
|
|
|
// Prepare buffer pointers
|
|
|
for (var i = 0; i < this._caps.maxVertexAttribs; i++) {
|
|
@@ -55732,7 +55732,7 @@ var BABYLON;
|
|
|
else {
|
|
|
var parameter = {};
|
|
|
BABYLON.Tools.DeepCopy(triggerOptions.parameter, parameter, ["mesh"]);
|
|
|
- if (triggerOptions.parameter.mesh) {
|
|
|
+ if (triggerOptions.parameter && triggerOptions.parameter.mesh) {
|
|
|
parameter._meshId = triggerOptions.parameter.mesh.id;
|
|
|
}
|
|
|
triggerObject.properties.push({ name: "parameter", targetType: null, value: parameter });
|
|
@@ -69518,7 +69518,7 @@ var BABYLON;
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
// Sets the default audio engine to Babylon JS.
|
|
|
- BABYLON.Engine.AudioEngineFactory = function (engine) { return new AudioEngine(engine); };
|
|
|
+ BABYLON.Engine.AudioEngineFactory = function (hostElement) { return new AudioEngine(hostElement); };
|
|
|
/**
|
|
|
* This represents the default audio engine used in babylon.
|
|
|
* It is responsible to play, synchronize and analyse sounds throughout the application.
|
|
@@ -69530,10 +69530,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
|
|
|
+ * @param hostElement defines the host element where to display the mute icon if necessary
|
|
|
*/
|
|
|
- function AudioEngine(engine) {
|
|
|
- if (engine === void 0) { engine = BABYLON.Engine.LastCreatedEngine; }
|
|
|
+ function AudioEngine(hostElement) {
|
|
|
+ if (hostElement === void 0) { hostElement = null; }
|
|
|
var _this = this;
|
|
|
this._audioContext = null;
|
|
|
this._audioContextInitialized = false;
|
|
@@ -69583,7 +69583,7 @@ var BABYLON;
|
|
|
this.canUseWebAudio = true;
|
|
|
}
|
|
|
var audioElem = document.createElement('audio');
|
|
|
- this._engine = engine;
|
|
|
+ this._hostElement = hostElement;
|
|
|
try {
|
|
|
if (audioElem && !!audioElem.canPlayType && audioElem.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/, '')) {
|
|
|
this.isMP3supported = true;
|
|
@@ -69641,7 +69641,6 @@ var BABYLON;
|
|
|
return result || Promise.resolve();
|
|
|
};
|
|
|
AudioEngine.prototype._initializeAudioContext = function () {
|
|
|
- var _this = this;
|
|
|
try {
|
|
|
if (this.canUseWebAudio) {
|
|
|
this._audioContext = new AudioContext();
|
|
@@ -69654,17 +69653,6 @@ var BABYLON;
|
|
|
// Do not wait for the promise to unlock.
|
|
|
this._triggerRunningState();
|
|
|
}
|
|
|
- else {
|
|
|
- if (this._audioContext && this._audioContext.resume) {
|
|
|
- this._resumeAudioContext().then(function () {
|
|
|
- _this._triggerRunningState();
|
|
|
- }).catch(function () {
|
|
|
- // Can not resume automatically
|
|
|
- // Needs user action
|
|
|
- _this.lock();
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
catch (e) {
|
|
@@ -69681,16 +69669,16 @@ var BABYLON;
|
|
|
this._resumeAudioContext()
|
|
|
.then(function () {
|
|
|
_this._tryToRun = false;
|
|
|
- _this.unlocked = true;
|
|
|
if (_this._muteButton) {
|
|
|
_this._hideMuteButton();
|
|
|
}
|
|
|
- // Notify users that the audio stack is unlocked/unmuted
|
|
|
- _this.onAudioUnlockedObservable.notifyObservers(_this);
|
|
|
}).catch(function () {
|
|
|
_this._tryToRun = false;
|
|
|
_this.unlocked = false;
|
|
|
});
|
|
|
+ // Notify users that the audio stack is unlocked/unmuted
|
|
|
+ this.unlocked = true;
|
|
|
+ this.onAudioUnlockedObservable.notifyObservers(this);
|
|
|
};
|
|
|
AudioEngine.prototype._triggerSuspendedState = function () {
|
|
|
this.unlocked = false;
|
|
@@ -69702,7 +69690,6 @@ var BABYLON;
|
|
|
if (this.useCustomUnlockedButton) {
|
|
|
return;
|
|
|
}
|
|
|
- this._canvas = this._engine.getRenderingCanvas();
|
|
|
this._muteButton = document.createElement("BUTTON");
|
|
|
this._muteButton.className = "babylonUnmuteIcon";
|
|
|
this._muteButton.id = "babylonUnmuteIconBtn";
|
|
@@ -69713,9 +69700,6 @@ var BABYLON;
|
|
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
|
document.body.appendChild(this._muteButton);
|
|
|
this._moveButtonToTopLeft();
|
|
|
- this._muteButton.addEventListener('mousedown', function () {
|
|
|
- _this._triggerRunningState();
|
|
|
- }, true);
|
|
|
this._muteButton.addEventListener('touchend', function () {
|
|
|
_this._triggerRunningState();
|
|
|
}, true);
|
|
@@ -69725,9 +69709,9 @@ var BABYLON;
|
|
|
window.addEventListener("resize", this._onResize);
|
|
|
};
|
|
|
AudioEngine.prototype._moveButtonToTopLeft = function () {
|
|
|
- if (this._canvas && this._muteButton) {
|
|
|
- this._muteButton.style.top = this._canvas.offsetTop + 20 + "px";
|
|
|
- this._muteButton.style.left = this._canvas.offsetLeft + 20 + "px";
|
|
|
+ if (this._hostElement && this._muteButton) {
|
|
|
+ this._muteButton.style.top = this._hostElement.offsetTop + 20 + "px";
|
|
|
+ this._muteButton.style.left = this._hostElement.offsetLeft + 20 + "px";
|
|
|
}
|
|
|
};
|
|
|
AudioEngine.prototype._hideMuteButton = function () {
|