问题
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
回答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.
回答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(" ");
}
来源:https://stackoverflow.com/questions/19270595/stop-youtube-video-on-back-button-of-windows-metro-app-8-1