Reputation: 384
I am trying to play a HTML iframe video but the video refuses to play unless i mute the sound.This is my the web view method.
private void playVideoOnWebView(String videoUrl) {
videoWebViewPlayer = findViewById(R.id.videoPlayerWebView);
videoWebViewPlayer.setVisibility(VISIBLE);
videoWebViewPlayer.getSettings().setJavaScriptEnabled(true);
videoWebViewPlayer.getSettings().getAllowContentAccess();
videoWebViewPlayer.getSettings().setDomStorageEnabled(true);
videoWebViewPlayer.getSettings().setAppCacheEnabled(true);videoWebViewPlayer.getSettings().setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
videoWebViewPlayer.getSettings().setDatabaseEnabled(true);
videoWebViewPlayer.getSettings().setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
videoWebViewPlayer.getSettings().setPluginState(WebSettings.PluginState.ON);
videoWebViewPlayer.getSettings().setDomStorageEnabled(true);
videoWebViewPlayer.setWebChromeClient(new WebChromeClient());
videoWebViewPlayer.loadUrl(videoUrl);
}
Thanks...
Upvotes: 3
Views: 1068
Reputation: 18022
As you say that if the video is muted it plays without a problem it seems to me you are trying to autoplay a video without following Chrome's autoplay policies:
The last one might be the cause, to allow autoplay from iframes (when the video is not mute) the allow
attribute must be set to autoplay
:
<iframe src="https://cross-origin.com/myvideo.html" allow="autoplay">
I also struggled autoplay restrictions some time ago.
Upvotes: 1