如何关闭自动播放功能

时间:2015-07-15 15:03:24

标签: html iframe video mp4 autoplay

我在iframe代码中嵌入了.mp4视频。我无法弄清楚如何关闭自动播放。我尝试了一切:autoplay =“false”,autoplay =“0”,autoplay ='false',autoplay ='0'但似乎没有任何效果。这是我的代码:

<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item behind" src='videos/cloud_computing.mp4' width='640' height='360' style='width:640px;height:360px;'></iframe>
</div>

在此之前有一段YouTube视频(没有自动播放),代码如下:

<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item behind" src='https://www.youtube.com/embed/v1uyQZNg2vE?enablejsapi=1&amp;html5=1&amp;hd=1&amp;wmode=transparent&amp;controls=1&amp;showinfo=0;rel=0;' width='640' height='360' style='width:640px;height:360px;'></iframe>
</div>

3 个答案:

答案 0 :(得分:1)

如果没有其他工作,请尝试添加

&autoStart=false

在你的src结束时。如果这不起作用,那么您可能必须使用其他媒介来嵌入您的视频。而是可以使用

<video>
   <source src="videos/cloud_computing.mp4" type="video/mp4">
</video>

答案 1 :(得分:1)

您需要在<video>标记围绕它,因为它不知道iframe是视频,因此autoplay永远不会有效。请尝试以下代码。

   <div class="embed-responsive embed-responsive-16by9">
          <iframe class="embed-responsive-item behind"> 
           <video src='videos/cloud_computing.mp4'
             width='640' height='360' style='width:640px;height:360px;' autoplay="0">
            </video>
        </iframe>
        </div>
  

请注意

我会使用autoplay="0"autoplay="1",因为Chrome无法识别autoplay="true"autoplay="false"

答案 2 :(得分:0)

我遇到了同样的问题,在朋友的帮助下我们得到了修复工作。看看这里的例子

&#13;
&#13;
$('.play-btn').on('click', function () {
    // Fetch the video iframe
    var $video = $('.video');

    // Extract the src
    var src = $video.data('src');

    // Add a src attr which should start the video
    $video.attr('src', src);
});

$('.stop-btn').on('click', function () {
    $('.video').removeAttr('src');
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe class="video" data-src="https://www.youtube.com/embed/DLzxrzFCyOs" type="mp4">
  </iframe>
<button class="play-btn" type="button">Play Video</button>
<button class="stop-btn" type="button">Stop Video</button>
&#13;
&#13;
&#13;

https://jsfiddle.net/BestByTest/2tfkhj04/

在这个例子中,youtube视频自动播放设置为关闭,有些视频没有这个选项,我发现的就是修复。也可以设置为模态,因此图像会打开视频。确保在模态打开后设置iframe以获取URL。这样您就无法以封闭模式播放视频。