2017-04-04 75 views
0

我使用一个Wordpress插件添加时间戳链接的视频,将自动搜索视频到一定的时间范围。seekTo()不是一个功能YouTube的iframe API错误

的Javascript:

 function onYouTubeIframeAPIReady(){ 

    console.log('Confirmation of call to onYouTubeIframeAPIReady()'); 

    var STT = { 
     settings: STTSettings, 
     media: undefined, 
     skipTo: undefined, 
     isHTML5: false, 
     isYoutube: true, 

     doHTML5Skip: function() { 
      STT.media.removeEventListener('canplaythrough', STT.doHTML5Skip); 
      STT.media.currentTime = STT.skipTo; 
      STT.media.play(); 
     }, 

     doYoutubeSkip: function() { 

      STT.media.seekTo(STT.skipTo); 
      STT.media.playVideo(); 
     } 

    }; 




    STTSkipTo = function(time) { 
     var audio  = document.getElementsByTagName('audio'), 
      video  = document.getElementsByTagName('video'), 
      iframe  = document.getElementsByTagName('iframe'), 
      timeArray = time.split(':').reverse(), 
      seconds  = parseInt(timeArray[0]), 
      minutes  = timeArray.length > 1 ? parseInt(timeArray[1]) : 0, 
      hours  = timeArray.length > 2 ? parseInt(timeArray[2]) : 0; 

     STT.skipTo = seconds + (minutes * 60) + (hours * 3600); 

     if (STT.media) { 
      console.log(STT.media.seekTo); 
      STT.doSkip(); 

      return; 
     } 

     if ((parseInt(STT.settings.link_audio) && audio.length) || 
      (parseInt(STT.settings.link_video) && video.length)) 
     { 
      STT.doSkip = STT.doHTML5Skip; 

      if (parseInt(STT.settings.link_audio) && audio.length) { 
       STT.media = audio[0]; 
      } else { 
       STT.media = video[0]; 
      } 

      STT.media.addEventListener('canplaythrough', STT.doHTML5Skip); 
      STT.media.load(); 
      STT.media.play(); 
      return; 
     } else if (parseInt(STT.settings.link_youtube && iframe.length)) { 
      // Inspect the iframes, looking for a src with youtube in the URI 
      for (var i = 0; i < iframe.length; i++) { 
       if (iframe[i].src.search('youtube') !== -1) { 
        // Set up the JS interface 
        STT.doSkip = STT.doYoutubeSkip; 

        iframe[0].id = 'stt-youtube-player'; 
        STT.media = new YT.Player('stt-youtube-player', { 
         events: { 
          onReady: STT.doYoutubeSkip 
         } 
        }); 
        return; 
       } 
      } 
     } 

     console.log('Skip to Timestamp: No media player found!'); 
     return; 
    } 

    } 

在我的本地,插件无缝工作,但在我的托管网站,我收到以下错误与堆栈如下:

Uncaught TypeError: STT.media.seekTo is not a function enter image description here

我认为,出于某种原因该网站无法加载依赖于YouTube iframe API的www-widgetapi.js,因此无法生成所需的功能定义。但是,我确实尝试在头文件中手动包含脚本,但它仍然无法工作。

如果有人知道任何其他wordpress插件,请咨询。

回答

0

根据此documentation,您需要设置player.seekTo(seconds:Number, allowSeekAhead:Boolean)的两个参数。

Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing , video cued , etc.), the player will play the video.

  • seconds参数标识球员应该提前到的时间。

    除非玩家已经下载了用户正在寻找的视频部分,否则玩家将在该时间之前前进到最接近的关键帧。

  • allowSeekAhead参数确定如果seconds参数指定当前缓冲的视频数据之外的时间,播放器是否将向服务器发出新的请求。

应该是这样:Player.seekTo(120, true)//120 seconds