-2

我知道这个话题有几个问题。我什至在这里得到了很好的答案。

问题如下。我有一段无法更改的代码,它显示了 youtube 视频。我必须适应它。

问题是 onPlayerStateChange() 函数永远不会启动。知道为什么会这样吗?

<script src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
var ytPlayer;
var idplayer;
function onYouTubePlayerReady(playerId) {
    ytPlayer = document.getElementById("ytPlayer");
}

function pauseVideo() {
  if (ytPlayer) {
    ytPlayer.stopVideo();
  }  
}

// when video ends
function onPlayerStateChange(event) {        
    if(event.data === 0) { 
    idplayer=document.getElementById("a_TMBLRWDLH").href;
        window.location.assign(idplayer);
    }
}

j$(document).ready(function(){


    j$('#' + Bnr_vars[0].banner).click(function(){

        if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))
{
    var info='<iframe width=\"600\" height=\"338\" src=\"http://www.youtube.com/embed/0Bmhjf0rKe8?rel=0&wmode=transparent&modestbranding=1&autoplay=1&enablejsapi=1\" frameborder=\"0\" allowfullscreen></iframe>';
    j$('#player').html(info);
}

});
</script>
4

1 回答 1

0

我有解决方案以防万一帮助某人。当我希望对话框出现时,我只需要创建新的 YT.Player。

j$(document).ready(function(){
    var Bnr_vars = [
        {
            "banner" : "teamworkRowersDLVidOpener",
            "closer" : "teamworkRowersDLVidCloser",
            "dialog" : "teamworkRowersDLVidDialog",
            "auto"   : "false"              // auto open TRUE or FALSE?
        }
    ];

    lightboxCreate(Bnr_vars); // create lightboxes based on array above 

    j$('#' + Bnr_vars[0].banner).click(function(){

        if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))
        {
            var info=new YT.Player('player', {
                height: '338',
                width: '600',
                videoId: '_Zmr0cUeNBY',
                playerVars : {
                    playerapiid:'player1',
                    rel: '0',
                    wmode: 'transparent',
                    modestbranding: '1'
                },
                events: {
                    'onReady': onPlayerReady,
                    'onStateChange': onPlayerStateChange
                }
            });
            j$('#player').html(info);
        }

    });
于 2013-08-23T20:49:27.453 回答