0

In my app I have view pager with many webview. In my web view have youtube or video player to play video. when I click back I call

webview.loadData("", "text/html", "utf-8");

It run very good,. But when I change page I can't stop play video. How I do to stop video when next or resturn a page?

Hoa.Tran
  • 737
  • 9
  • 24

1 Answers1

1
@Override
protected void onPause() {
    super.onPause();
    if (isFinishing()) {
        webView.loadUrl("about:blank");
    } else {
        webView.onPause();
        webView.pauseTimers();
    }
}

@Override
protected void onResume() {
    super.onResume();
    webView.resumeTimers();
    webView.onResume();
}

It pauses the webview if the view is only paused, but clears it when the activity is finished. This requires at least API 11 (Honeycomb).

Jitesh Prajapati
  • 2,661
  • 4
  • 28
  • 47