-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. #609
Comments
@goldfire I've been having this problem with various Android browsers and iOS. The issue is that mobile devices require a gesture to be the origin for calling the This commit introduces wrapping At one point in time, Firefox (probably version 13) had an issue solved by wrapping the I've tested and confirmed that removing the Can we take it out? I will be forced to patch howler with this fix for my own use until it's resolved. |
I was using this library in an Angular 2 project. I wrapped the functions such as So a button click event would go to the Angular service and the service would then call the howler object When I removed this wrapper and directly called Ex: I change to this:
Instead of:
|
@swaheed2 Will this work when you enforce html5 mode? (e.g. set Howler seems to take different paths depending on where, when and how you're using it. I'm wanting HTML5 to be enforced. |
@marcusstenbeck yes I also enforced html5 mode |
Note: I've only tested it on Android Nexus 6 Chrome browser and it works |
I'll see if I can make a jsbin tomorrow with the error. |
Here's a jsbin that will not work on my Android devices. |
I am getting this error on Chrome Android. other mobile browsers not tested. It seems to match this Chrome issue : https://bugs.chromium.org/p/chromium/issues/detail?id=178297 I can understand if this behavior is Chrome's fault, but Howler should provide a way to catch/listen/detect this error in some way, so that we can know that the play() call didn't work and adjust the UI accordingly. |
@implicitdef Try removing the Change this setTimeout(function() {
node.play();
// Setup the new end timer.
if (timeout !== Infinity) {
self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
}
if (!internal) {
self._emit('play', sound._id);
}
}, 0); into this // setTimeout(function() {
node.play();
// Setup the new end timer.
if (timeout !== Infinity) {
self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
}
if (!internal) {
self._emit('play', sound._id);
}
// }, 0); |
@marcusstenbeck No, in my case it doesn't change everything. My problem is not that this is restricted, it's more that the restriction is undetectable, forcing me to tweak my code based on the user agent. Maybe I should file a separate issue ? |
@implicitdef - It is in the howler documentation that a touch is required to play sounds on certain devices - https://github.com/goldfire/howler.js#mobile-playback I'm not sure what more Howler can do? Throw a console log error each time a sound is attempted to be played but the browser still has webaudio locked? |
They could wrap their play() call in a try catch, and fire a 'playerror' event, for instance, similar to the existing 'loaderror' event. |
Oh, yeah. Autoplaying is a different issue than what you have @implicitdef. I'm strictly interested in playing triggered by a user gesture. |
Filed a separate issue. Sorry for the noise. |
…l stack On mobile, the play event needs to be triggered by a user gesture. By setting a timeout the call stack containing the user tap gesture is lost. Since this was added way back to support something in Firefox 13 it could most likely be removed without negative impact. goldfire#609
I've created a pull request with the fix that solves it in my testing conditions. #694 |
#694 has now been merged into master and will be included in 2.0.3. |
Does anyone still having this issue? I've just upgraded to the latest version (2.0.5) but still having the same problem. |
@volkan-umg yup, i got the same on canary 65 |
I am getting this error on Android and Iphone. I am calling play based on a button click, but still get this error thrown. Any suggestions?
The text was updated successfully, but these errors were encountered: