summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Mönig <jens@moenig.org>2014-02-04 06:55:25 -0800
committerJens Mönig <jens@moenig.org>2014-02-04 06:55:25 -0800
commit268ece61031560010acebfa85580e879c9017782 (patch)
treea6f74c9f36f4280723fa64ee324c19062eada658
parent590ce704fcc7a805caad79149231edb5f3fcadae (diff)
parentb4eb1d1864df81692d40a059336b070c4006e209 (diff)
downloadsnap-268ece61031560010acebfa85580e879c9017782.tar.gz
snap-268ece61031560010acebfa85580e879c9017782.zip
Merge pull request #311 from brettle/master
Fixes issue #310 - play note block fails on Firefox
-rw-r--r--objects.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/objects.js b/objects.js
index 1c9a166..fd19bd6 100644
--- a/objects.js
+++ b/objects.js
@@ -5653,17 +5653,20 @@ Note.prototype.setupContext = function () {
if (this.audioContext) { return; }
var AudioContext = (function () {
// cross browser some day?
- return window.AudioContext ||
+ var ctx = window.AudioContext ||
window.mozAudioContext ||
window.msAudioContext ||
window.oAudioContext ||
window.webkitAudioContext;
+ if (!ctx.prototype.hasOwnProperty('createGain'))
+ ctx.prototype.createGain = ctx.prototype.createGainNode;
+ return ctx;
}());
if (!AudioContext) {
throw new Error('Web Audio API is not supported\nin this browser');
}
Note.prototype.audioContext = new AudioContext();
- Note.prototype.gainNode = Note.prototype.audioContext.createGainNode();
+ Note.prototype.gainNode = Note.prototype.audioContext.createGain();
Note.prototype.gainNode.gain.value = 0.25; // reduce volume by 1/4
};
@@ -5671,17 +5674,21 @@ Note.prototype.setupContext = function () {
Note.prototype.play = function () {
this.oscillator = this.audioContext.createOscillator();
+ if (!this.oscillator.start)
+ this.oscillator.start = this.oscillator.noteOn;
+ if (!this.oscillator.stop)
+ this.oscillator.stop = this.oscillator.noteOff;
this.oscillator.type = 0;
this.oscillator.frequency.value =
Math.pow(2, (this.pitch - 69) / 12) * 440;
this.oscillator.connect(this.gainNode);
this.gainNode.connect(this.audioContext.destination);
- this.oscillator.noteOn(0); // deprecated, renamed to start()
+ this.oscillator.start(0);
};
Note.prototype.stop = function () {
if (this.oscillator) {
- this.oscillator.noteOff(0); // deprecated, renamed to stop()
+ this.oscillator.stop(0);
this.oscillator = null;
}
};