Javascript - Youtube API检测已删除/已屏蔽的视频

时间:2013-01-30 13:15:56

标签: javascript jquery youtube-api

我如何检查 - >如果视频被删除/私有或嵌入不被允许?

DEMO: http://jsbin.com/eyexah/15/edit
YT API DOC: https://developers.google.com/youtube/js_api_reference

JS代码

var params = {
    allowScriptAccess: "always"
},
    atts = {
        id: "youtube_player"
    };

swfobject.embedSWF('http://www.youtube.com/v/SJmrqKOsIpM?enablejsapi=1&playerapiid=ytplayer&version=3&autoplay=1', 'youtube', '425', '356', '8', null, null, params, atts);

function onPlayerStateChange(e) {
    if (e !== 1) {
        return;
    }

    var availableQualityLevels = ytp.getAvailableQualityLevels();
    console.log(availableQualityLevels);
}

function onYouTubePlayerReady() {
    window.ytp = document.getElementById("youtube_player");
    ytp.addEventListener('onStateChange', 'onPlayerStateChange')

};

1 个答案:

答案 0 :(得分:0)

您可以在播放时通过使用播放器API聆听onError回调来执行此操作:https://developers.google.com/youtube/iframe_api_reference#onError

此博客文章详细介绍了如何使用Data API提前检测某些限制:http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html

域级白名单或黑名单仍未通过Data API>

公开