在离子2 app中使用iframe播放youtube视频 [英] Playing youtube video using iframe in ionic 2 app

查看:180
本文介绍了在离子2 app中使用iframe播放youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ionic 2应用中,我尝试使用iframe嵌入一个YouTube视频。代码如下所示:

In an Ionic 2 app, I am trying to embed one youtube video using iframe. The code looks like this:

<iframe width="320" height="315" src="https://www.youtube.com/embed/VIDEOID?autoplay=1&controls=1" frameborder="0" allowfullscreen></iframe>

然而,当我导航到该页面时,我收到此错误。我找不到如何解决这个问题的好答案。

However when I navigate to the page I am getting this error. I can't find a good answer how to fix this.


XMLHttpRequest无法加载 https://googleads.g.doubleclick.net/pagead/id 。当credentials标志为true时,不能在'Access-Control-Allow-Origin'标头中使用通配符'*'。因此,不允许访问 https://www.youtube.com 。 XMLHttpRequest的凭据模式由withCredentials属性控制。

XMLHttpRequest cannot load https://googleads.g.doubleclick.net/pagead/id. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'https://www.youtube.com' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

不确定如何解决此问题。任何帮助/领导都将不胜感激。

Not sure how to fix this. Any help/lead would be appreciated.

BTW,我正在开发/测试Chrome浏览器开发工具。

BTW, I am developing/testing in chrome browser developer tool.

谢谢,

推荐答案

您最好将此添加到您的config.xml:

You better add this to your config.xml:

<preference name="AllowInlineMediaPlayback" value="true"/>
<access origin="*" subdomains="true" /> 

还要确保你的Android清单有:

Also make sure your android manifest has:

<application android:hardwareAccelerated="true" ...>

这篇关于在离子2 app中使用iframe播放youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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