Skip to content

Commit 269af69

Browse files
committed
Added extra checks to Sound.play to stop it throwing DOM Exception Error 11 if the sound.readyState wasn't set or the sound was invalid. Also wrapped stop() call in a try catch`.
1 parent 2641e2e commit 269af69

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Version 2.2.2 - "Alkindar" - in development
7373

7474
### New Features
7575

76+
* Phaser.Loader now supports BLOB urls for audio files (thanks @aressler38 #1462)
77+
7678
### Updates
7779

7880
* TypeScript definitions fixes and updates (thanks @clark-stevenson)
@@ -99,6 +101,7 @@ Android browser does not support Full Screen.
99101
* P2.postBroadphaserHandler updated to avoid skipping final 2 pairs.
100102
* The P2 World constructor wouldn't let you use your own config unless you specified both the gravity *and* broadphase. Now allows one or both (thanks @englercj #1412)
101103
* The RandomDataGenerator could be seeded with an array of values. However if the array contained a zero it would stop seeding from that point (thanks @jpcloud @pnstickne #1456)
104+
* Added extra checks to Sound.play to stop it throwing DOM Exception Error 11 if the `sound.readyState` wasn't set or the sound was invalid. Also wrapped `stop()`` call in a `try catch`.
102105

103106
For details about changes made in previous versions of Phaser see the full Change Log at https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md
104107

src/sound/Sound.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,21 @@ Phaser.Sound.prototype = {
456456
return this;
457457
}
458458

459-
if (this.isPlaying && !this.allowMultiple && (this.override || forceRestart))
459+
if (this._sound && this.isPlaying && !this.allowMultiple && (this.override || forceRestart))
460460
{
461-
if (this.usingWebAudio)
461+
if (this.usingWebAudio && this._sound.readyState > 0)
462462
{
463463
if (typeof this._sound.stop === 'undefined')
464464
{
465465
this._sound.noteOff(0);
466466
}
467467
else
468468
{
469-
this._sound.stop(0);
469+
try {
470+
this._sound.stop(0);
471+
}
472+
catch (e) {
473+
}
470474
}
471475
}
472476
else if (this.usingAudioTag)

0 commit comments

Comments
 (0)