Check audio context ctor before constructing

This commit is contained in:
Daniel Imms
2018-02-21 14:39:43 -08:00
parent 1972bf4bb3
commit db8ba17147
+4 -4
View File
@@ -21,8 +21,9 @@ export class SoundManager implements ISoundManager {
}
public playBellSound(): void {
if (!this._audioContext) {
this._audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioContextCtor: typeof AudioContext = (<any>window).AudioContext || (<any>window).webkitAudioContext;
if (!this._audioContext && audioContextCtor) {
this._audioContext = new audioContextCtor();
}
if (this._audioContext) {
@@ -33,8 +34,7 @@ export class SoundManager implements ISoundManager {
bellAudioSource.connect(context.destination);
bellAudioSource.start(0);
});
}
else {
} else {
console.warn('Sorry, but the Web Audio API is not supported by your browser. Please, consider upgrading to the latest version');
}
}