Skip to content

Commit af65660

Browse files
author
Lanny McNie
committed
Suppressed errors with getter/setters in older browsers.
1 parent 46fc905 commit af65660

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

VERSIONS.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version NEXT
2+
************************************************************************************************************************
3+
- suppressing errors in WebAudioPlugin and HTMLAudioPlugin in old browsers that do not properly support object.defineProperty
4+
15
Version 0.5.0 [September 25, 2013]
26
************************************************************************************************************************
37
CRITICAL (may break existing content):

src/soundjs/HTMLAudioPlugin.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,22 @@ this.createjs = this.createjs || {};
435435
p.offset = 0;
436436
p.delay = 0;
437437
p._volume = 1;
438-
Object.defineProperty(p, "volume", {
439-
get: function() {
440-
return this._volume;
441-
},
442-
set: function(value) {
443-
if (Number(value) == null) {return;}
444-
value = Math.max(0, Math.min(1, value));
445-
this._volume = value;
446-
this.updateVolume();
447-
}
448-
});
438+
// IE8 has Object.defineProperty, but only for DOM objects, so check if fails to suppress errors
439+
try {
440+
Object.defineProperty(p, "volume", {
441+
get: function() {
442+
return this._volume;
443+
},
444+
set: function(value) {
445+
if (Number(value) == null) {return;}
446+
value = Math.max(0, Math.min(1, value));
447+
this._volume = value;
448+
this.updateVolume();
449+
}
450+
});
451+
} catch (e) {
452+
// dispatch message or error?
453+
};
449454
p.pan = 0;
450455
p.duration = 0;
451456
p.remainingLoops = 0;

src/soundjs/WebAudioPlugin.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ this.createjs = this.createjs || {};
608608
* @default 1
609609
*/
610610
p._volume = 1;
611-
Object.defineProperty(p, "volume", {
611+
// IE8 has Object.defineProperty, but only for DOM objects, so check if fails to suppress errors
612+
try {
613+
Object.defineProperty(p, "volume", {
612614
get: function() {
613615
return this._volume;
614616
},
@@ -618,7 +620,10 @@ this.createjs = this.createjs || {};
618620
this._volume = value;
619621
this.updateVolume();
620622
}
621-
});
623+
});
624+
} catch (e) {
625+
// dispatch message or error?
626+
};
622627

623628
/**
624629
* The pan of the sound, between -1 (left) and 1 (right). Note that pan does not work for HTML Audio.
@@ -631,21 +636,27 @@ this.createjs = this.createjs || {};
631636
* @default 0
632637
*/
633638
p._pan = 0;
634-
Object.defineProperty(p, "pan", {
635-
get: function() {
636-
return this._pan;
637-
},
638-
set: function(value) {
639-
if (!this.owner.capabilities.panning || Number(value) == null) {return false;}
639+
// IE8 has Object.defineProperty, but only for DOM objects, so check if fails to suppress errors
640+
try {
641+
Object.defineProperty(p, "pan", {
642+
get: function() {
643+
return this._pan;
644+
},
645+
set: function(value) {
646+
if (!this.owner.capabilities.panning || Number(value) == null) {return false;}
647+
648+
value = Math.max(-1, Math.min(1, value)); // force pan to stay in the -1 to 1 range
649+
// Note that panning in WebAudioPlugin can support 3D audio, but our implementation does not.
650+
this._pan = value; // Unfortunately panner does not give us a way to access this after it is set http://www.w3.org/TR/webaudio/#AudioPannerNode
651+
this.panNode.setPosition(value, 0, -0.5); // z need to be -0.5 otherwise the sound only plays in left, right, or center
652+
}
653+
});
654+
} catch (e) {
655+
// dispatch message or error?
656+
};
640657

641-
value = Math.max(-1, Math.min(1, value)); // force pan to stay in the -1 to 1 range
642-
// Note that panning in WebAudioPlugin can support 3D audio, but our implementation does not.
643-
this._pan = value; // Unfortunately panner does not give us a way to access this after it is set http://www.w3.org/TR/webaudio/#AudioPannerNode
644-
this.panNode.setPosition(value, 0, -0.5); // z need to be -0.5 otherwise the sound only plays in left, right, or center
645-
}
646-
});
647658

648-
/**
659+
/**
649660
* The length of the audio clip, in milliseconds.
650661
* Use {{#crossLink "SoundInstance/getDuration:method"}}{{/crossLink}} to access.
651662
* @property pan

0 commit comments

Comments
 (0)