Youtube iFrame API的cueVideoById无法在移动设备上运行?

时间:2012-12-18 11:36:22

标签: javascript iframe youtube-api

我正在开发一个网站,其中涉及在移动设备上播放嵌入式Youtube视频片段。 The API声明cueVideoById支持定义startSeconds和endSeconds参数,只要你使用对象语法这样做:

player.cueVideoById({videoId:String, 
                     startSeconds:Number, 
                     endSeconds:Number, 
                     suggestedQuality:String}):Void

这在桌面浏览器上运行良好,但在Android和Windows Phone 8中我都收到标准的Youtube消息,说明该视频目前无法使用。如果我将cueVideoById切换回这样的参数语法,一切正常:

player.cueVideoById(videoId:String, 
                    startSeconds:Number, 
                    suggestedQuality:String):Void

...但是我再也无法访问endSeconds了。有没有人知道原因,甚至更好的解决方法?我正在使用的代码基于API中的基本入门示例:

<!DOCTYPE html>
<html>
  <body>
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="player"></div>

    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "//www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

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

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {

      event.target.cueVideoById("u1zgFlCw8Aw", 10, "medium");   // Works on mobile
      /*
        event.target.cueVideoById({ videoId: "u1zgFlCw8Aw",         // Doesn't work on mobile
                                    startSeconds: "10",
                                    endSeconds: "15",
                                    suggestedQuality: "medium"});
        */
        event.target.playVideo();
      }

    </script>
  </body>
</html>

2 个答案:

答案 0 :(得分:0)

我补充说:

function onPlayerStateChange(event) {

}

现在只有第一个例子适用于我,就像你在评论中所述。

答案 1 :(得分:0)

现在它已经在android jellybean上为我工作了......

我补充说:

function onPlayerStateChange(event){

}