1

I need to play video in html5 video tag in Android webView. I used android method

webView.loadUrl("javascript:" + url);

previously, but decided replace it with modern method

webView.evaluateJavascript(url, null);

And I faced on issue with evaluateJavascript() method:

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

But with loadUrl() this issue was not fired. How to play video using evaluateJavascript() and html video tag?

4
  • why? if it works with the other method use the other method. what is the real problem? Commented Nov 3, 2016 at 13:26
  • @Pamblam evaluateJavascript() allows to get result which return JS code. loadUrl() does not allow this. Commented Nov 3, 2016 at 13:33
  • use a JavascriptInterface to allow your webview JS to communicate with host App.. Commented Nov 3, 2016 at 13:36
  • @Pamblam JavascriptInterface allow to call Java methods from JS side. I need vice versa - call JS methods from Java side. Commented Nov 3, 2016 at 13:42

1 Answer 1

1

on the webview try this, should work after this:

myWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.