Domexception: Play() Can Only Be Initiated by a User Gesture

DOMException: play() can only be initiated by a user gesture

This probably has to do with the trusted security model. Certain operations are only allowed if they're initiated by the user. This is for instance how a lot of popup blockers work. Likewise Chrome may want to protect users against auto-playing videos.

Make sure you call videoElement.play() in an event handler that is associated to a gesture.

// this should be ok
videoElement.addEventListener("click", function () {
videoElement.play();
});

// this is not ok
setTimeout(function () {
videoElement.play();
});

Since your function is called in navigator.getUserMedia it would seem strange to ask for user input again. Have you tried using autoplay on the video element?

What means 'initiated by a user gesture.' in element.requestFullscreen() API?

A Chrome extension (Ghostery – Privacy Ad Blocker) was the problem. After disabling the extension, the requestFullscreen API worked fine again.

Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture

I had to experiment with Chrome playing sounds. It turned out that even after a user gesture (such as click) it waits for 1000ms and if no sound was played it throws the exception above. In my case the problem was coming from asynchronous track URL loading.

But it also turned out that after the first track is played chrome doesn't care anymore for this 1000ms delay and you can call play programmatically with any timeout you want.

So the solution was to play a micro almost zero-second long muted sound from static resources after the very first time a user clicks on a track and after that load a desired track URL.

Hope it helps or someone finds other solutions.

Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. on website in chrome-android

If you are attempting to "auto-play" audio, i.e., on load or page display etc., then it is usually going to be blocked by mobile devices. iOS does this basically all the time.

http://www.schillmania.com/projects/soundmanager2/doc/technotes/#mobile-device-limitations

For HTML5 audio load and playback to work, you need to call the audio stuff immediately from a user touch/click/gesture, and no setTimeout() or other asynchronous stuff is allowed in-between.



Related Topics



Leave a reply



Submit