Webview 中 iframe 中的 YouTube 视频在导航后继续播放 [英] YouTube video in an iframe in Webview continues to play after navigation

查看:18
本文介绍了Webview 中 iframe 中的 YouTube 视频在导航后继续播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不在我的一个 Windows 8 xaml 应用程序中嵌入一个 YouTube 视频.我在 webView 中添加了一个 iframe,如 this.现在我的问题是,当我离开页面时,YouTube 视频会继续播放.由于导航后当前视图中不存在 WebView 的页面,因此我也无法访问 iframe.一旦我离开页面,有没有办法以某种方式停止视频?

谢谢和问候,拉米亚

解决方案

您想暂停视频(并缓存页面)以便他们回到原来的位置吗?

如果不是,那么一个不太优雅(但有效)的选项:

<块引用>

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

如果您想暂停视频,我相信您应该能够通过在 YouTube IFrame API 中包含一些 JavaScript 并结合 OnNavigatingFrom 和对 InvokeScript.

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

解决方案

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.

这篇关于Webview 中 iframe 中的 YouTube 视频在导航后继续播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆