3

所以我有我的代码,它检测播放器何时停止问题是当结束时我无法从 0 秒开始播放我正在使用包含 html5 视频的 Iframe 嵌入,这是代码!

<div id="youtube-fs"><iframe id="youtube-iframe" type="text/html" src="http://www.youtube.com/embed/LYL0lzmrvk8?enablejsapi=1&html5=1&autoplay=1&showinfo=0&controls=0&rel=0&wmode=transparent&vq=hd1080&hd=1&loop=1" frameborder="0" wmode="Opaque" ></iframe> <script type="text/javascript">
    <!--
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      var player;
      function onYouTubePlayerAPIReady() { player = new YT.Player('youtube-iframe', { events: { 'onStateChange': onPlayerStateChange } }); }
      function onPlayerReady(event) { event.target.playVideo(); }
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.ENDED) { player.playVideoAt(0); } // Play from 0 seconds
      }
        -->
    </script>

    </div>

有任何想法吗?也许是寻求?或东西提前谢谢你!

用过player.seekTo(1, true);的有效

4

1 回答 1

6

尝试这个

 function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.ENDED) { 
          player.seekTo(0); 
          player.playVideo();

        } // Play from 0 seconds
      }

http://plnkr.co/aoSupfT7vXGGoM99sNwl

于 2014-07-11T07:06:04.087 回答