Skip to content

Commit afda0fe

Browse files
committed
The new Web Audio Panning feature breaks WebAudio on Safari (OSX and iOS). The stero panner node is now only created if supported. Fix phaserjs#5460
1 parent 92085bb commit afda0fe

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

src/sound/webaudio/WebAudioSound.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ var WebAudioSound = new Class({
9494
/**
9595
* Panner node responsible for controlling this sound's pan.
9696
*
97+
* Doesn't work on iOS / Safari.
98+
*
9799
* @name Phaser.Sound.WebAudioSound#pannerNode
98100
* @type {StereoPannerNode}
99101
* @private
100102
* @since 3.50.0
101103
*/
102-
this.pannerNode = manager.context.createStereoPanner();
104+
this.pannerNode = null;
103105

104106
/**
105107
* The time at which the sound should have started playback from the beginning.
@@ -175,9 +177,18 @@ var WebAudioSound = new Class({
175177

176178
this.muteNode.connect(this.volumeNode);
177179

178-
this.volumeNode.connect(this.pannerNode);
180+
if (manager.context.createStereoPanner)
181+
{
182+
this.pannerNode = manager.context.createStereoPanner();
179183

180-
this.pannerNode.connect(manager.destination);
184+
this.volumeNode.connect(this.pannerNode);
185+
186+
this.pannerNode.connect(manager.destination);
187+
}
188+
else
189+
{
190+
this.volumeNode.connect(manager.destination);
191+
}
181192

182193
this.duration = this.audioBuffer.duration;
183194

@@ -908,6 +919,8 @@ var WebAudioSound = new Class({
908919
/**
909920
* Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).
910921
*
922+
* Always returns zero on iOS / Safari as it doesn't support the stereo panner node.
923+
*
911924
* @name Phaser.Sound.WebAudioSound#pan
912925
* @type {number}
913926
* @default 0
@@ -918,13 +931,24 @@ var WebAudioSound = new Class({
918931

919932
get: function ()
920933
{
921-
return this.pannerNode.pan.value;
934+
if (this.pannerNode)
935+
{
936+
return this.pannerNode.pan.value;
937+
}
938+
else
939+
{
940+
return 0;
941+
}
922942
},
923943

924944
set: function (value)
925945
{
926946
this.currentConfig.pan = value;
927-
this.pannerNode.pan.setValueAtTime(value, this.manager.context.currentTime);
947+
948+
if (this.pannerNode)
949+
{
950+
this.pannerNode.pan.setValueAtTime(value, this.manager.context.currentTime);
951+
}
928952

929953
this.emit(Events.PAN, this, value);
930954
}
@@ -933,6 +957,8 @@ var WebAudioSound = new Class({
933957
/**
934958
* Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).
935959
*
960+
* Note: iOS / Safari doesn't support the stereo panner node.
961+
*
936962
* @method Phaser.Sound.WebAudioSound#setPan
937963
* @fires Phaser.Sound.Events#PAN
938964
* @since 3.50.0

0 commit comments

Comments
 (0)