2017-04-26 118 views
0

我试图嵌入我的离子型应用程序的视频,但错误时显示的页面加载:嵌入YouTube视频造成CORS错误

GET https://redirector.googlevideo.com/videoplayback?pcm2cms=yes&key=yt6&ei=5HE…QBGK&c=WEB&cver=1.20170425&cmo=pf=1&range=0-622&rn=15&playerretry=3&rbuf=0 404 (Not Found) 

XMLHttpRequest cannot load https://redirector.googlevideo.com/videoplayback?pcm2cms=yes&key=yt6&ei=5HE…QBGK&c=WEB&cver=1.20170425&cmo=pf=1&range=0-622&rn=15&playerretry=3&rbuf=0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.youtube.com' is therefore not allowed access. The response had HTTP status code 404. 

,这里是我的html代码:

<iframe width="420" height="315" src="{{video}}" ></iframe> 

这里的controller.js代码:

$scope.video = "https://www.youtube.com/embed/RP-mvJE9EQM"; 

我加入这在我的app.js文件:

$sceDelegateProvider.resourceUrlWhitelist(['self', new RegExp('^(http[s]?):\/\/(w{3}.)?youtube\.com/.+$')]); 

,这在我的config.xml文件:

<allow-navigation href="*.youtube.com" /> 
<preference name="AllowInlineMediaPlayback" value="true" /> 

我应该如何去解决呢?我错过了什么?

回答

0

用http代替https尝试。 另外,尽量把这个线内的index.html

<head> 
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * data: 'unsafe-inline'; connect-src * 'unsafe-inline'; frame-src *;"> 
</head> 

要小心,因为它允许的一切,当你使用它。 有关内容安全策略的更多信息:

https://developers.google.com/web/fundamentals/security/csp/

希望这有助于。

+0

感谢输入。我在index.html中添加了一行代码并使用了http,但它仍然无法正常工作。 –

0

我增加:

<access origin="*" /> 

config.xml中