0

我有一个 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>
4

1 回答 1

1

它应该是 videoPlayer.pauseVideo();

于 2016-09-29T12:40:00.013 回答