Fixed a problem with the video TAB not playing automatically under android webview

  • 2020-05-27 07:10:41
  • OfStack

Under android webview

video of html5 sets the autoplay property

Or use the play method in document ready

You can't make it play automatically

Only webview's onPageFinished method can be used to solve this problem. The code is as follows:
mPlayer.setWebViewClient(new WebViewClient() { 
// autoplay when finished loading via javascript injection 
public void onPageFinished(WebView view, String url) { mPlayer.loadUrl("javascript:(function() { var videos = document.getElementsByTagName('video'); for(var i=0;i<videos.length;i++){videos[i].play();}})()"); } 

The problem can be solved by putting the above code in //here.
public class PlayerActivity extends Activity { 
protected void onCreate(Bundle savedInstanceState) { 

Related articles: