onYouTubeIframeAPIReady youtube api没有打电话?

时间:2017-12-07 07:08:56

标签: youtube youtube-api youtube-iframe-api

您好,我想知道为什么我的youtube api无效。 我的程序在console.log上正常工作(“make youtube”);

所以,我搜索了很多我喜欢这样的解决方案“”确保你的onYouTubeIframeAPIReady函数在全局级别可用,而不是嵌套(隐藏)在另一个函数中。“”

但我无法理解任何人请更新我的代码段。 这是我的代码。

var playYoutubeVideos = function (index, videoId) {
    if (typeof videoId == "undefined") {
        videoId = $('#list').find('li[index="'+index+'"]').attr('data-video_id');
    }
    jwplayer(playerId).stop();
    $('.video-div').hide();
    $('.transcript-container').hide();
    $('.youtube_video_div').show();

    var tag = document.createElement('script');
    tag.src = 'https://www.youtube.com/iframe_api';
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    /*$('.youtube_video_div').append('<center><iframe class="video_frame" src="https://www.youtube.com/embed/'+videoId+'?&autoplay=1" frameborder="0" allowfullscreen></iframe></center>');
    animateFooterList(index);*/
    console.log(videoId);
}   

    var vdid=videoId;
  // 3. This function creates an <iframe> (and YouTube player)
      //after the API code downloads.
      var player;
      //function onYouTubeIframeAPIReady() {debugger;
        console.log("making youtube");
        player = new YT.Player('yt_fram', {
          height: '390',
          width: '640',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      //}

    console.log(player);
    function stopVideo() {
        player.stopVideo();
      }
    $('.video-div').hide();
    $('.transcript-container').hide();
    $('.youtube_video_div').show();

    index = index + 1;
    nextvideoId = $('#list').find('li[index="'+index+'"]').attr('data-video_id');
    jwplayer(playerId).play();

    if($('#list li[index='+index+']').hasClass('video_plus'))
    {
        playThis(index,'video_plus',nextvideoId);
        //return;
    }
    else if($('#list li[index='+index+']').hasClass('ext_video'))
    {
        playThis(index,'ext_video','');
        //return;
    }
    playThis(index,'','');
    

// 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        console.log("youtube player ready");
        event.target.playVideo();
      }

      // 5. The API calls this function when the player's state changes.
      //    The function indicates that when playing a video (state=1),
      //    the player should play for six seconds and then stop.
      var done = false;
      function onPlayerStateChange(event) {
          console.log("youtube player state change");
            console.log("event");
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
      }
      

utube api没有打电话

0 个答案:

没有答案