使用youtube API中的按钮播放和暂停iframe视频



我有一个iframe youtube视频,我想播放它并使用按钮暂停,这是我到目前为止所拥有的,但它似乎不起作用,有人能告诉我我犯了什么错误吗。

<body>

<div class="youtubePlayer" id="youtubePlayer">
<iframe id="videoPlayer" width="340" height="200"      src="https://www.youtube.com/embed/-0oZNWif_jk?list=PLD0qnaHPys3v_j-yGcnA3JJoTCFz_aK7s?enablejsapi=1&html5=1" frameborder="0" allowfullscreen>  </iframe>
</div>

<button id="play-btn">Play</button>
<button id="stop-btn">Stop</button>

<script>

var videoPlayer;
function onYouTubePlayerAPIReady() {
  videoPlayer = new YT.Player('videoPlayer', {
      events: {
          //calls function when player is ready
        'onReady': onPlayerReady
        }
      });
}
function onPlayerReady(event) {
    //bind
    var playButton = document.getElementById("play-btn");
    playButton.addEventListener("click", function() {
        videoPlayer.playVideo();    
    });
    var pauseButton = document.getElementById("stop-btn");
    pauseButton.addEventListener("click", function() {
        player.pauseVideo();
    });
}

var tag = document.createElement('script');
tag.src = "//www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

</script>
</body>

它应该是videoPlayer.pauseVideo();

相关内容

  • 没有找到相关文章