
Question:
I had to embed a YouTube video in one of my windows 8 xaml apps. I added an iframe in a webView like <a href="http://silverspoted.blogspot.com/2012/12/to-embed-youtube-videos-in-windows-8.html" rel="nofollow">this</a>. Now my problem is that when I navigate away from the page the YouTube video continues to play. Since the page in which the WebView is not present in the current view after navigation, I am not able to access the iframe as well. Is there a way to stop the video somehow once I navigate away from the page?
Thanks and Regards, Ramya
Answer1:Do you want to pause the video (and cache the page) so they can come back to where they were?
If not, then a less than elegant (but effective) option:
<blockquote> protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
wv.NavigateToString("");
}
</blockquote>
If you want to pause the video, I believe you should be able to accomplish that goal by including some JavaScript in the YouTube IFrame API in combination with <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.page.onnavigatingfrom.aspx" rel="nofollow">OnNavigatingFrom</a> and a call to <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.invokescript.aspx" rel="nofollow">InvokeScript</a>.