在 ionic 2 应用程序中使用 iframe 播放 youtube 视频 [英] Playing youtube video using iframe in ionic 2 app
问题描述
在 Ionic 2 应用程序中,我尝试使用 iframe 嵌入一个 youtube 视频.代码如下所示:
<iframe width="320" height="315" src="https://www.youtube.com/embed/VIDEOID?autoplay=1&controls=1" frameborder="0" allowfullscreen></iframe>
但是,当我导航到该页面时,出现此错误.我找不到如何解决这个问题的好答案.
<块引用>XMLHttpRequest 无法加载 https://googleads.g.doubleclick.net/pagead/id一>.当凭证标志为真时,不能在Access-Control-Allow-Origin"标头中使用通配符*".因此,不允许访问 Origin 'https://www.youtube.com'.XMLHttpRequest 的凭据模式由 withCredentials 属性控制.
不知道如何解决这个问题.任何帮助/领导将不胜感激.
顺便说一句,我正在 chrome 浏览器开发者工具中进行开发/测试.
谢谢,
你最好把这个添加到你的 config.xml 中:
<access origin="*" subdomains="true"/>
还要确保您的 android 清单具有:
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 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, I am developing/testing in chrome browser developer tool.
Thanks,
You better add this to your config.xml:
<preference name="AllowInlineMediaPlayback" value="true"/>
<access origin="*" subdomains="true" />
Also make sure your android manifest has:
<application android:hardwareAccelerated="true" ...>
这篇关于在 ionic 2 应用程序中使用 iframe 播放 youtube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!