Skip to content

Commit 009653d

Browse files
authored
Allow web audio unlock via mouse click
Scenario in Chrome for desktop: 1. Game loads 2. Game automatically starts some playing music (web audio, not HTML5 audio) - If the user pressed a key or clicked the canvas with the mouse before the music started playing, they now hear the music. - If the user did not press a key, nor click the canvas with the mouse before the music started playing, they will not hear the music until they press a key, however no amount of mouse clicking will let them hear the music. This fix allows a mouse click to get the music playing audibly, even if they didn't interact with the canvas (via keyboard or mouse) before it started playing.
1 parent d37aa4b commit 009653d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

lib/impact/sound.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ ig.SoundManager = ig.Class.extend({
3535
this.audioContext = new AudioContext();
3636
this.boundWebAudioUnlock = this.unlockWebAudio.bind(this);
3737
ig.system.canvas.addEventListener('touchstart', this.boundWebAudioUnlock, false);
38+
ig.system.canvas.addEventListener('mousedown', this.boundWebAudioUnlock, false);
3839
}
3940
},
4041

4142
unlockWebAudio: function() {
4243
ig.system.canvas.removeEventListener('touchstart', this.boundWebAudioUnlock, false);
44+
ig.system.canvas.removeEventListener('mousedown', this.boundWebAudioUnlock, false);
4345

4446
// create empty buffer
4547
var buffer = this.audioContext.createBuffer(1, 1, 22050);

0 commit comments

Comments
 (0)