Sachin
Sachin

Reputation: 217

Youtube video not stopping in a webview inside a fragment with view pager

Problem Statement: I have a view pager with pager adapter containing 4 fragments. In the last fragment, I have a webview dedicated to play you tube embed videos. When video is been played and I scroll the viewpager or I exit the app by pressing back button (as I have a single activity), Video doesnt stop in a webview. I have seen one answer at here. It doesn't work. But my question is even if it works, where should I put that onPause code of the webview? I have tried it in onPageScrolled method of pager adapter but it doesn't work there either. Any help is appreciated. TIA.

Upvotes: 3

Views: 1010

Answers (1)

crubio
crubio

Reputation: 6422

You have to pause your webview in your fragment. Don't forget to resume it or it won't work the second time:

@Override
public void onResume()
{
    super.onResume();
    mWebView.onResume();
}

@Override
public void onPause()
{
    super.onPause();
    mWebView.onPause();
}

Upvotes: 1

Related Questions