0

I have a page on which i am showing multiple youtube videos as webviews. When i play any video, then correspoding video starts playing. But When I click on the back button of the App i should be stop then but its running in background(can hear voice of video).

here is the code of back button:

protected void GoBack(object sender, RoutedEventArgs e)
{
        ((Frame)Window.Current.Content).GoBack();
} 

Tell me how i can dispose of this webview or can stop video.

Thanks

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
Awn Ali
  • 1,361
  • 1
  • 17
  • 31

2 Answers2

1

First make sure that the page is finalized; most probably by detaching all the event handlers you manually attached before. Then (sooner or later) the page will be finalized which in turns disposes of the webview.

A similar effect would be achieved by forward navigating the webview to an empty html page.

HDW Production
  • 1,402
  • 10
  • 13
0

Here is the solution: Invoke the UnLoaded event of WebView - webView.Unloaded += webView_UnLoaded;

Then change the source of the webview in webView_UnLoaded event handler: Here is my code:

private void webView_UnLoaded(object sender, RoutedEventArgs e)
    {
        WebView webView = (WebView)sender;
        webView.Source = new Uri(" ");
    }
Awn Ali
  • 1,361
  • 1
  • 17
  • 31