Stop YouTube Video on Back Button of Windows Metro App 8.1

纵饮孤独 提交于 2019-12-13 07:09:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!