我似乎无法获取我的youtube javascript给我正确的视频错误。例如,以下代码应该给我错误代码150,但它给我0。
在HTML上嵌入代码
<object width='710' height='400' style='z-index: 1;'>
<param name='movie' value='https://www.youtube.com/v/Ze8bj80qL_I?version=3&enablejsapi=1&autoplay=1&rel=0&wmode=transparent'></param>
<param name='allowFullScreen' value='true'></param>
<param name='allowScriptAccess' value='always'></param>
<param name='wmode' value='transparent'></param>
<embed src='https://www.youtube.com/v/Ze8bj80qL_I?version=3&enablejsapi=1&autoplay=1&rel=0&wmode=transparent' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='710' height='400' id='myytplayer' wmode='transparent'></embed>
</object>
使用Javascript:
function onPlayerError(event) {
alert(event);
}
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
ytplayer.addEventListener("onError", "onPlayerError");
$(ytplayer).attr({
"src" : url.replace('?rel=0', '')+"?wmode=transparent",
"wmode" : "Opaque"
});
}
答案 0 :(得分:0)
我不知道为什么,但只有在YouTube IFrame API与HTML5播放器一起使用时才能获得正确的错误代码。
HTML:
<div id="player"></div>
JavaScript的:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onPlayerError(event) {
alert("Error code " + event.data);
}
function onYouTubeIframeAPIReady() {
console.log("start");
var player;
player = new YT.Player('player', {
videoId: 'Ze8bj80qL_I',
playerVars: {
'autoplay': 1,
'controls': 0,
'html5': 1
},
events: {
'onError': onPlayerError
}
});
}
错误代码 100 :
找不到要求的视频。视频有此错误 已被删除(出于任何原因)或已被标记为私人。
Here is the jsfiddle.在GC30中测试过。