goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.85k stars 2.23k forks source link

Cannot enable sound on multi touch events on iOS #795

Closed damy90 closed 4 years ago

damy90 commented 7 years ago

I can enable the sound on iOS if I tap with one finger, but Howler.ctx.resume() does not work if I use multi touch. Also, the sounds pile up until I click with one finger and are played all at once. The same problem happens on the Spatial Audio demo on the main page: https://howlerjs.com/ If I click with two fingers I can navigate the map just like if I was using one finger, but the audio doesn't start. If this is an iOS issue and it can't be fixed maybe the library should at least drop the sounds that failed to start. Affected platforms: iOS iOS 9 and 10. It works on iOS 8. Here's the code I use to enable sound:


document.body.addEventListener('touchend', contextResume);
function contextResume() {
    if (('ctx' in Howler && Howler.ctx !== null) && Howler.ctx.state === 'suspended') {
        Howler.ctx.resume();
    }
}
damy90 commented 7 years ago

Probably can't be fixed "Warning: To prevent unsolicited downloads over cellular networks at the user's expense, embedded media cannot be played automatically in Safari on iOS—the user always initiates playback. A controller is automatically supplied on iPhone or iPod touch once playback in initiated, but for iPad you must either set the controls attribute or provide a controller using JavaScript." Source: https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html#//apple_ref/doc/uid/TP40009523-CH2-SW1

goldfire commented 4 years ago

Closing due to inactivity. If this is still an issue, reply with more info and I'll reopen.