ios – Android: "Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture-ThrowExceptions

Exception or error:

I’m working on a HTML5 video player automation(test page is a html page). I tried to call myPlayer.Play() through Javascript. On Android, however, I got this error:

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

after sending a Play() request.

I know autoplay is disabled on lots of devices on purpose to save users bandwidth. But the first time Play() seems also needed the user gesture. What is the workaround for this so that I can automate testing for the player device?

How to solve:

You can disable this security function. For example:

WebView mWebView = (WebView) findViewById(R.id.web_view);
mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);

Available in API versions 17 and above

More info see this

Leave a Reply

Your email address will not be published. Required fields are marked *