Skip to content

Commit ec3bd4c

Browse files
committed
The WebAudioSoundManager will now listen for 'click' events on the document body, as well as touch events, before resuming the AudioContext.
1 parent 1414b77 commit ec3bd4c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The Loader has been given an overhaul to improve its performance and extensibili
7373
* We have removed the TextureManager.addAtlasPyxel method and related parser. It didn't work anyway and no-one seems to use Pyxel any more. If we get enough demand we can consider adding it back.
7474
* When adding an Audio Sprite to the Sound Manager it will now respect the `loop` property, if set in the source JSON.
7575
* The Texture class has a new method `getDataSourceImage` which will return the raw image data of the data source.
76+
* The WebAudioSoundManager will now listen for 'click' events on the document body, as well as touch events, before resuming the AudioContext, in order to deal with the changes made in Chrome v66 not playing audio until a user gesture is received, even on desktop.
7677

7778
### Bug Fixes
7879

src/sound/webaudio/WebAudioSoundManager.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var WebAudioSoundManager = new Class({
7373
*/
7474
this.destination = this.masterMuteNode;
7575

76-
this.locked = this.context.state === 'suspended' && 'ontouchstart' in window;
76+
this.locked = this.context.state === 'suspended' && ('ontouchstart' in window || 'onclick' in window);
7777

7878
BaseSoundManager.call(this, game);
7979

@@ -85,7 +85,7 @@ var WebAudioSoundManager = new Class({
8585

8686
/**
8787
* Method responsible for instantiating and returning AudioContext instance.
88-
* If an instance of an AudioContext class was provided trough the game config,
88+
* If an instance of an AudioContext class was provided through the game config,
8989
* that instance will be returned instead. This can come in handy if you are reloading
9090
* a Phaser game on a page that never properly refreshes (such as in an SPA project)
9191
* and you want to reuse already instantiated AudioContext.
@@ -133,7 +133,7 @@ var WebAudioSoundManager = new Class({
133133
},
134134

135135
/**
136-
* Unlocks Web Audio API on iOS devices on the initial touch event.
136+
* Unlocks Web Audio API on the initial input event.
137137
*
138138
* Read more about how this issue is handled here in [this article](https://medium.com/@pgoloskokovic/unlocking-web-audio-the-smarter-way-8858218c0e09).
139139
*
@@ -150,13 +150,15 @@ var WebAudioSoundManager = new Class({
150150
{
151151
document.body.removeEventListener('touchstart', unlock);
152152
document.body.removeEventListener('touchend', unlock);
153+
document.body.removeEventListener('click', unlock);
153154

154155
_this.unlocked = true;
155156
});
156157
};
157158

158159
document.body.addEventListener('touchstart', unlock, false);
159160
document.body.addEventListener('touchend', unlock, false);
161+
document.body.addEventListener('click', unlock, false);
160162
},
161163

162164
/**

0 commit comments

Comments
 (0)