Reputation: 3885
I have a simple WebView rendering an HTML5 page that has video playing in the backdrop.. I set the video to play automatically by
browser.getSettings().setMediaPlaybackRequiresUserGesture(false);
It works except the "Start Video Playback" button is still there. When I click the button it does nothing as the video is already playing.. is there any way to hide this button? I searched and found nothing.
EDIT: this worked!
browser.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
browser.loadUrl("javascript:document.getElementById('VideoClipPlayButton').click();"
}
});
Upvotes: 2
Views: 1981
Reputation: 6203
I found a solution to your problem. You just have to add a new Javascript that will turn off the button when the page is loaded . Codes below has been tested and works. I checked in C # but Java is very similar so it must work.
JAVA
wv.loadUrl("http://app.singular.live/webchannels/298/onair");
wv.getSettings().setMediaPlaybackRequiresUserGesture(false);
wv.getSettings().setPluginState(PluginState.ON);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView view, String url)
{
//here create new JS find element in page (button) and set visibility to hidden
wv.loadUrl("javascript:document.getElementById('VideoClipPlayButton').style.visibility = 'hidden';");
}
});
C# (XAMARIN)
Button button = FindViewById<Button>(Resource.Id.MyButton);
WebView wv = FindViewById<WebView>(Resource.Id.webView1);
wv.Settings.JavaScriptEnabled = true;
wv.LoadUrl("http://app.singular.live/webchannels/298/onair");
wv.Settings.MediaPlaybackRequiresUserGesture = false;
wv.Settings.PluginsEnabled = true;
wv.Settings.SetPluginState(WebSettings.PluginState.On);
wv.Settings.JavaScriptEnabled = true;
wv.Settings.AllowFileAccess = true;
button.Click += (s, e) =>
{
wv.LoadUrl("javascript:document.getElementById('VideoClipPlayButton').style.visibility = 'hidden';");
};
Upvotes: 1