暂停后如何停止加载嵌入的YouTube视频

时间:2016-12-30 08:03:17

标签: javascript jquery html5 youtube embed

如果我暂停了youtube视频加载,该怎么办?

暂停视频后,视频加载进度条也会停止。

<iframe width="560" height="315" src="https://www.youtube.com/embed/Ggh_y-33Eso" frameborder="0" allowfullscreen></iframe>

1 个答案:

答案 0 :(得分:0)

You may want to review through the Youtube JavaScript API Reference docs.

When you embed your video(s) on the page, you will need to pass this parameter:

http://www.youtube.com/v/VIDEO_ID?version=3&enablejsapi=1
If you want a stop all videos button, you can setup a javascript routine to loop through your videos and stop them:

player.stopVideo()
This does involve keeping track of all the page IDs for each video on the page. Even simpler might be to make a class and then use jQuery.each.

$('#myStopClickButton').click(function(){
  $('.myVideoClass').each(function(){
    $(this).stopVideo();
  });
});