Skip to content

Commit

Permalink
[#1079] Fix issue where suppressPlayButton blocks load
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 24, 2018
1 parent 434664c commit 697f22d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sandbox/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var logger = ex.Logger.getInstance();
logger.defaultLevel = ex.LogLevel.Debug;

// Create an the game container
var game = new ex.Engine({ width: 800, height: 600, canvasElementId: 'game', suppressHiDPIScaling: false });
var game = new ex.Engine({ width: 800, height: 600, canvasElementId: 'game', suppressHiDPIScaling: false, suppressPlayButton: true });
game.setAntialiasing(false);
game.isDebug = true;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ O|===|* >________________>\n\
var loadingComplete: Promise<any>;
if (loader) {
this._loader = loader;
this._loader.suppressPlayButton = this._suppressPlayButton;
this._loader.suppressPlayButton = this._suppressPlayButton || this._loader.suppressPlayButton;
this._loader.wireEngine(this);
loadingComplete = this.load(this._loader);
} else {
Expand Down
17 changes: 13 additions & 4 deletions src/engine/Util/WebAudio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AudioContextFactory } from '../Resources/Sound/AudioContext';
import { Promise } from '../Promises';
import { Promise, PromiseState } from '../Promises';
import { Logger } from './Log';

export interface LegacyWebAudioSource {
playbackState: string;
Expand All @@ -24,7 +25,10 @@ export class WebAudio {
if (WebAudio._unlocked || !AudioContextFactory.create()) {
return promise.resolve(true);
}

const unlockTimeoutTimer = setTimeout(() => {
Logger.getInstance().warn('Excalibur was unable to unlock the audio context, audio probably will not play in this browser.');
promise.resolve();
}, 200);
const audioContext = AudioContextFactory.create();
audioContext.resume().then(
() => {
Expand Down Expand Up @@ -57,10 +61,15 @@ export class WebAudio {
}
}, 0);

promise.resolve();
clearTimeout(unlockTimeoutTimer);
if (promise.state() === PromiseState.Pending) {
promise.resolve();
}
},
() => {
promise.reject(false);
if (promise.state() === PromiseState.Pending) {
promise.reject(false);
}
}
);

Expand Down

0 comments on commit 697f22d

Please sign in to comment.