Skip to content

Commit

Permalink
[FIX] Sound in iOS should now begin automatically when the user touch…
Browse files Browse the repository at this point in the history
…es the screen so no further need to add custom touch handlers to start playing sounds
  • Loading branch information
vkalpias committed Jan 26, 2016
1 parent 6e8e3c6 commit 07d3be5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sound/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ pc.extend(pc, function () {
} else if (typeof webkitAudioContext !== 'undefined') {
this.context = new webkitAudioContext();
}

if (this.context) {
var context = this.context;
// iOS only starts sound as a response to user interaction
var iOS = /iPad|iPhone|iPod/.test(navigator.platform);
if (iOS) {
// Play an inaudible sound when the user touches the screen
// This only happens once
var unlock = function () {
var buffer = context.createBuffer(1, 1, 22050);
var source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination);
source.start(0);

// no further need for this so remove the listener
window.removeEventListener('touchend', unlock);
};

window.addEventListener('touchend', unlock);
}
}
}
this.listener = new pc.Listener(this);

Expand Down

0 comments on commit 07d3be5

Please sign in to comment.