1. <tfoot id='ymFfi'></tfoot>
        <bdo id='ymFfi'></bdo><ul id='ymFfi'></ul>
      <legend id='ymFfi'><style id='ymFfi'><dir id='ymFfi'><q id='ymFfi'></q></dir></style></legend>
      <i id='ymFfi'><tr id='ymFfi'><dt id='ymFfi'><q id='ymFfi'><span id='ymFfi'><b id='ymFfi'><form id='ymFfi'><ins id='ymFfi'></ins><ul id='ymFfi'></ul><sub id='ymFfi'></sub></form><legend id='ymFfi'></legend><bdo id='ymFfi'><pre id='ymFfi'><center id='ymFfi'></center></pre></bdo></b><th id='ymFfi'></th></span></q></dt></tr></i><div id='ymFfi'><tfoot id='ymFfi'></tfoot><dl id='ymFfi'><fieldset id='ymFfi'></fieldset></dl></div>

      1. <small id='ymFfi'></small><noframes id='ymFfi'>

        Youtube iFrame API 'YT 未定义'

        时间:2023-09-06

          • <legend id='8NJMt'><style id='8NJMt'><dir id='8NJMt'><q id='8NJMt'></q></dir></style></legend>
              <tbody id='8NJMt'></tbody>
            <i id='8NJMt'><tr id='8NJMt'><dt id='8NJMt'><q id='8NJMt'><span id='8NJMt'><b id='8NJMt'><form id='8NJMt'><ins id='8NJMt'></ins><ul id='8NJMt'></ul><sub id='8NJMt'></sub></form><legend id='8NJMt'></legend><bdo id='8NJMt'><pre id='8NJMt'><center id='8NJMt'></center></pre></bdo></b><th id='8NJMt'></th></span></q></dt></tr></i><div id='8NJMt'><tfoot id='8NJMt'></tfoot><dl id='8NJMt'><fieldset id='8NJMt'></fieldset></dl></div>
          • <tfoot id='8NJMt'></tfoot>

            1. <small id='8NJMt'></small><noframes id='8NJMt'>

                <bdo id='8NJMt'></bdo><ul id='8NJMt'></ul>
                • 本文介绍了Youtube iFrame API 'YT 未定义'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将此代码放入模块函数中:

                  I'm trying to put this code in an module function:

                  $(document).ready(function()
                      {
                          VIDEO.onYouTubeIframeAPIReady();
                  }
                  
                  
                          var VIDEO = (function (my, $){
                  var tag = document.createElement('script');
                  var onPlayerStateChange;
                    tag.src = "https://www.youtube.com/iframe_api";
                    var firstScriptTag = document.getElementsByTagName('script')[0];
                    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
                  
                    var player;
                  
                  
                     my.onYouTubeIframeAPIReady =function() {
                      player = new YT.Player('player', {
                        height: '490',
                        width: '880',
                        videoId: SONG.getArtistId(),
                        playerVars: { controls:1, showinfo: 0, rel: 0, showsearch: 0, iv_load_policy: 3 },
                        events: {
                          'onReady': onPlayerReady,
                          'onStateChange': onPlayerStateChange,
                          'onError': catchError
                        }
                      });
                    }
                  
                    function onPlayerReady(event) {
                  
                  
                    if(typeof(SONG.getArtistId()) == undefined)
                    {
                      console.log("undefineeeed"); 
                    } 
                  
                  
                      event.target.playVideo();   
                    }
                  
                    var done = false;
                    function onPlayerStateChange(event) {
                      if (event.data == YT.PlayerState.PLAYING && !done) {
                        // setTimeout(stopVideo, 6000);
                        done = true;
                      }
                      if(event.data == YT.PlayerState.ENDED)
                      {
                        location.reload();
                      }
                    }
                  
                    function catchError(event)
                    {
                      if(event.data == 100) console.log("De video bestaat niet meer");
                    }
                  
                    function stopVideo() {
                      player.stopVideo();
                    }
                  
                    return my;
                  
                  }(VIDEO || {}, jQuery));
                  

                  问题是:即使它是自动执行的,也没有任何反应,并且 iFrame 也没有显示.我正在尝试这样做,因为它是作业的一部分.我们必须在模块中工作.

                  The problem is: even it's self-executing, nothing happens and the iFrame is not shown. I'm trying to do this because it's part of an assignment. We have to work in modules.

                  推荐答案

                  你需要简化代码:

                  HTML

                  <div id="player"></div>
                  

                  Javascript

                  $(document).ready( function() {
                    console.log( "ready!" );
                    loadPlayer();
                  });
                  
                  function getArtistId() {
                    return 'l-gQLqv9f4o';
                  }
                  
                  function loadPlayer() { 
                    if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
                  
                      var tag = document.createElement('script');
                      tag.src = "https://www.youtube.com/iframe_api";
                      var firstScriptTag = document.getElementsByTagName('script')[0];
                      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
                  
                      window.onYouTubePlayerAPIReady = function() {
                        onYouTubePlayer();
                      };
                  
                    } else {
                  
                      onYouTubePlayer();
                  
                    }
                  }
                  
                  var player;
                  
                  function onYouTubePlayer() {
                    player = new YT.Player('player', {
                      height: '490',
                      width: '880',
                      videoId: getArtistId(),
                      playerVars: { controls:1, showinfo: 0, rel: 0, showsearch: 0, iv_load_policy: 3 },
                      events: {
                        'onStateChange': onPlayerStateChange,
                        'onError': catchError
                      }
                    });
                  }
                  
                    var done = false;
                    function onPlayerStateChange(event) {
                      if (event.data == YT.PlayerState.PLAYING && !done) {
                        // setTimeout(stopVideo, 6000);
                        done = true;
                      } else if (event.data == YT.PlayerState.ENDED) {
                        location.reload();
                      }
                    }
                  
                    function onPlayerReady(event) {
                  
                      //if(typeof(SONG.getArtistId()) == undefined)
                      //{
                      //  console.log("undefineeeed"); 
                      /

                    <bdo id='068Qe'></bdo><ul id='068Qe'></ul>

                    <small id='068Qe'></small><noframes id='068Qe'>

                      1. <tfoot id='068Qe'></tfoot>

                          <tbody id='068Qe'></tbody>

                        <legend id='068Qe'><style id='068Qe'><dir id='068Qe'><q id='068Qe'></q></dir></style></legend>
                        <i id='068Qe'><tr id='068Qe'><dt id='068Qe'><q id='068Qe'><span id='068Qe'><b id='068Qe'><form id='068Qe'><ins id='068Qe'></ins><ul id='068Qe'></ul><sub id='068Qe'></sub></form><legend id='068Qe'></legend><bdo id='068Qe'><pre id='068Qe'><center id='068Qe'></center></pre></bdo></b><th id='068Qe'></th></span></q></dt></tr></i><div id='068Qe'><tfoot id='068Qe'></tfoot><dl id='068Qe'><fieldset id='068Qe'></fieldset></dl></div>