I have an issue with WebView, basically I am loading in a forum that has embedded videos in places, if you play a video then rotate the device the video keeps playing in the background and you can get to it to stop it. This also occurs when you minimize the app. Is there a way to stop this?
This is my WebView code I am using.
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.view = (WebView) findViewById(R.id.webView);
view.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.contains("grcade")) {
view.loadUrl(url);
view.getSettings().setJavaScriptEnabled(true);
return true;
} else {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
}
});
view.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
if(savedInstanceState == null){
String url = "http://grcade.co.uk";
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
view.getSettings().setSupportZoom(true);
view.getSettings().setBuiltInZoomControls(true);
view.getSettings().setDisplayZoomControls(false);
view.getSettings().setLoadWithOverviewMode(true);
view.setBackgroundColor(Color.WHITE);
}
final SwipeRefreshLayout pulltoRefresh = (SwipeRefreshLayout) findViewById(R.id.pullToRefresh);
pulltoRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
view.reload();
pulltoRefresh.setRefreshing(false);
}
});
}
@Override
public void onSaveInstanceState (Bundle outState)
{
super.onSaveInstanceState(outState);
view.saveState(outState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
view.restoreState(savedInstanceState);
view.getSettings().setJavaScriptEnabled(true);
}
//Main WebView Panel End
Any help would be appreciated as I am very confused, I am stopped it occuring with going back but the same method wont work as adding it in causes the app revert to the default webview URL rather than reloading the page the user was on.
Thanks.