Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: "Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture [duplicate]

Tags:

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?

like image 704
yiran Avatar asked Sep 10 '15 23:09

yiran


1 Answers

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

like image 117
AndreyNik Avatar answered Oct 21 '22 09:10

AndreyNik