嵌入youtube视频会导致CORS错误 [英] embedding youtube video results in CORS error
本文介绍了嵌入youtube视频会导致CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将视频嵌入我的离子应用程序,但是在加载页面时出现错误:
i'm trying to embed a video in my ionic app, but errors shows up when the page is loaded:
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代码:
here's my html code:
<iframe width="420" height="315" src="{{video}}" ></iframe>
这是controller.js代码:
here's the controller.js code:
$scope.video = "https://www.youtube.com/embed/RP-mvJE9EQM";
我将此添加到了我的app.js文件中:
i added this in my app.js file:
$sceDelegateProvider.resourceUrlWhitelist(['self', new RegExp('^(http[s]?):\/\/(w{3}.)?youtube\.com/.+$')]);
,这在我的config.xml文件中:
and this in my config.xml file:
<allow-navigation href="*.youtube.com" />
<preference name="AllowInlineMediaPlayback" value="true" />
我应该如何解决这个问题?我想念什么吗?
how should i go about solving this? am i missing something?
推荐答案
我添加了:
<access origin="*" />
在config.xml中
in config.xml
这篇关于嵌入youtube视频会导致CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文