YouTube video in an iframe in Webview continues to play after navigation

青春壹個敷衍的年華 提交于 2019-12-11 16:48:08

问题


I had to embed a YouTube video in one of my windows 8 xaml apps. I added an iframe in a webView like this. 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


回答1:


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:

    protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
    {
        base.OnNavigatingFrom(e);
        wv.NavigateToString("");
    }

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 OnNavigatingFrom and a call to InvokeScript.



来源:https://stackoverflow.com/questions/13757186/youtube-video-in-an-iframe-in-webview-continues-to-play-after-navigation

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