Youtube IFrame API onError fires with error code 150 for videos from Vevo
让我解释一下我的情况。我想使用Youtube IFrame API在我的网站上嵌入一些视频。
我在此页面上用id wdGZBRAwW74(https://www.youtube.com/watch?v=wdGZBRAwW74)测试了该视频:Youtube IFrame Player演示。而且行得通。
我尝试以下示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <!DOCTYPE html> <html> <body> <!-- 1. The <iframe> (and video player) will replace this tag. --> // 2. This code loads the IFrame Player API code asynchronously. var tag = document.createElement('script'); tag.src ="//www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); // 3. This function creates an <iframe> (and YouTube player) // after the API code downloads. var player; function onYouTubeIframeAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: 'wdGZBRAwW74', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange, 'onError': onPlayerError } }); } // 4. The API will call this function when the video player is ready. function onPlayerReady(event) { event.target.playVideo(); } // 5. The API calls this function when the player's state changes. // The function indicates that when playing a video (state=1), // the player should play for six seconds and then stop. var done = false; function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING && !done) { setTimeout(stopVideo, 6000); done = true; } } function onPlayerError(event){ console.log(event.data); } function stopVideo() { player.stopVideo(); } </body> </html> |
在我的本地主机上有一些虚拟主机域,我得到了结果:
我知道错误150代表"请求的视频的所有者不允许其在嵌入式播放器中播放"。但是我看到它在情况1、3、4下仍然可以工作,那是什么意思?
似乎Vevo的所有视频都与此问题有关。我不确定Vevo是否定义了嵌入视频的政策。
问题可能出在我的域名music.com上,但我不确定将Vevo的视频嵌入网站上是否存在某些域名规则。
如果我为我的网站购买了一个域名怎么办,但出现错误150,这太糟糕了。 :(
以前有没有人处理这个?请给我一些解决方案。预先感谢。
注意:此错误仅在Vevo的视频上发生。
内容所有者可以设置允许/拒绝嵌入的域名白/黑名单。无法解决这些限制。
此博客文章全面介绍了有关内容限制的更多信息:http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html