From 0f5bcc71ef5f2109aba7c66f440f50725492d897 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 13 Feb 2018 10:46:13 -0700 Subject: [PATCH] fixed safari support --- fta.js | 7 +++++-- smith.js | 7 +++++-- src/ftaplayer.ts | 7 +++++-- src/player.ts | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fta.js b/fta.js index d607000..d775fa8 100644 --- a/fta.js +++ b/fta.js @@ -233,10 +233,13 @@ var FTAPlayer = (function () { FTAPlayer.prototype.play = function () { var _this = this; try { - this.ctx = new AudioContext(); + this.ctx = new (window.AudioContext || window.webkitAudioContext)(); + if (this.ctx == undefined) { + throw new Error("No audio support!"); + } } catch (e) { - alert('No audio support'); + alert(e.message); return; } this.audioNode = this.ctx.createScriptProcessor(0, 0, 2); diff --git a/smith.js b/smith.js index f178506..0437a6e 100644 --- a/smith.js +++ b/smith.js @@ -250,10 +250,13 @@ var Player = (function () { Player.prototype.play = function () { var _this = this; try { - this.ctx = new AudioContext(); + this.ctx = new (window.AudioContext || window.webkitAudioContext)(); + if (this.ctx == undefined) { + throw new Error("No audio support!"); + } } catch (e) { - alert('No audio support'); + alert(e.message); return; } this.audioNode = this.ctx.createScriptProcessor(0, 0, 2); diff --git a/src/ftaplayer.ts b/src/ftaplayer.ts index c2a1976..3522ac7 100644 --- a/src/ftaplayer.ts +++ b/src/ftaplayer.ts @@ -68,9 +68,12 @@ class FTAPlayer { public play(): void { try { - this.ctx = new AudioContext(); + this.ctx = new ((window).AudioContext || (window).webkitAudioContext)(); + if (this.ctx == undefined) { + throw new Error("No audio support!"); + } } catch (e) { - alert('No audio support'); + alert(e.message); return; } this.audioNode = this.ctx.createScriptProcessor(0, 0, 2); diff --git a/src/player.ts b/src/player.ts index 56e2021..8fb8d68 100644 --- a/src/player.ts +++ b/src/player.ts @@ -85,9 +85,12 @@ class Player { public play(): void { try { - this.ctx = new AudioContext(); + this.ctx = new ((window).AudioContext || (window).webkitAudioContext)(); + if (this.ctx == undefined) { + throw new Error("No audio support!"); + } } catch (e) { - alert('No audio support'); + alert(e.message); return; } this.audioNode = this.ctx.createScriptProcessor(0, 0, 2);