سؤال

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

هل كانت مفيدة؟

المحلول 2

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(" ");
    }

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top