第二次无法调用功能

时间:2016-12-19 17:15:59

标签: javascript jquery youtube

我正在使用YouTube API制作YouTube视频的动态播放列表。例如:https://jsfiddle.net/r2zrsd9f/

这是我的代码:

function YTPlayeri(ytId){
var tag = document.createElement("script");
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var player;
window.onYouTubeIframeAPIReady = function() {
    player = new YT.Player("playeri", {
        "height": "315",
        "width": "560",
        "videoId": ytId,
        "events": {
            "onReady": onPlayerReady,
            "onStateChange": onPlayerStateChange
        }
    });
}
function onPlayerReady(event) {
    event.target.playVideo();
}
var myTimer; 
function onPlayerStateChange(event){
    if(event.data==1){
        myTimer = setInterval(function(){ 
            var time;
            time = player.getCurrentTime();
            $(".time_wrapper").text(time);
        }, 100);
    }
    else{
        clearInterval(myTimer);
    }
}
return this;
}

$("a.iframe_loader").click(function(){
    var ytId = $(this).attr("data-ytid");
    $(".player_wrapper").html('<div id="playeri"></div>');
    YTPlayeri(ytId);
});

请帮我点击第二次点击功能并获得播放时间

0 个答案:

没有答案