1

我正在使用多个HTMLLoader将 youtube 视频嵌入 Air 应用程序(每个加载程序一个),当我添加两个以上时,它会导致 API 中的所有玩家超过第二个错误。播放器似乎工作正常,但从未调用事件,并且 player.pauseVideo 未定义。

TypeError: Result of expression 'b' [undefined] is not an object.
at http://s.ytimg.com/yts/jsbin/www-embed-player-vflJ4hakx.js : 206
at http://s.ytimg.com/yts/jsbin/www-embed-player-vflJ4hakx.js : 205
at http://s.ytimg.com/yts/jsbin/www-embed-player-vflJ4hakx.js : 204
at http://s.ytimg.com/yts/jsbin/www-embed-player-vflJ4hakx.js : 199

我的嵌入代码:

function SetupYoutubePlayer(divName, videoID) {
    _videoID = videoID;
    _divName = divName;
    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}

var _videoID;
var _divName;

var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player(_divName, {
        height: '100%',
        width: '100%',
        wmode: 'opaque',
        autohide: '1',
        modestbranding: '1',
        frameborder: "0",
        showinfo: '0',
        videoId: _videoID,
        playerVars: { 
            'wmode': 'opaque', 
            'rel': 0, 
            'autohide': 1,
            'modestbranding': 1,
            'frameborder': 0,
            'showinfo': 0,
        },
        events: {
            'onStateChange': onPlayerStateChange
        }
    });
}
4

1 回答 1

0

看起来您重复调用以下行:

var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

这些只需要执行一次,就可以引入YT.Player定义和相关的 API。如果您确保只执行一次,事情是否按预期工作?

于 2013-06-25T16:15:35.703 回答