Html 禁用 html5 视频自动播放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19664622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable html5 video autoplay
提问by kkgzjjmj
How can I disable html5 video autoplay?
如何禁用 html5 视频自动播放?
what I've tried:
我试过的:
<video width="640" height="480" controls="controls" type="video/mp4" autoplay="false" preload="none"><source src="http://mydomain.com/mytestfile.mp4">Your browser does not support the video tag.</video>
回答by caulitomaz
I'd remove the autoplay attribute, since if the browser finds the autoplay string, it autoplays!
我会删除 autoplay 属性,因为如果浏览器找到自动播放字符串,它就会自动播放!
The autoplay is not a boolean type.
自动播放不是布尔类型。
Also, the type goes inside the source, like this:
此外,类型进入源代码,如下所示:
<video width="640" height="480" controls preload="none">
<source src="http://example.com/mytestfile.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Reference: http://www.w3.org/TR/html-markup/video.html
回答by rsnr4u
remove the autoplay in video tag. use code like this
删除视频标签中的自动播放。使用这样的代码
<video class="embed-responsive-item" controls>
<source src="http://example.com/video.mp4">
Your browser does not support the video tag.
</video>
it is 100% working
它是 100% 工作的
回答by anita
Try adding autostart="false"
to your source tag.
尝试添加autostart="false"
到您的源标签。
<video width="640" height="480" controls="controls" type="video/mp4" preload="none">
<source src="http://example.com/mytestfile.mp4" autostart="false">
Your browser does not support the video tag.
</video>
回答by Dhaval Mistry
just use preload="none"
in your video tag and video will stop autoplay when the page is loading.
只需preload="none"
在您的视频标签中使用,视频就会在页面加载时停止自动播放。
回答by Eduard Florinescu
Indeed setting autoplay
to false
doesn't help some videos will play anyway. See this case in fiddle.
确实设置autoplay
为false
无济于事,无论如何都会播放一些视频。在小提琴中看到这个案例。
You might want to do by code something in the line of if you want to pause all the videos:
如果您想暂停所有视频,您可能希望通过代码执行以下操作:
videos = document.querySelectorAll("video");
for(video of videos) {
video.pause();
}
Of course the above case will not work if the video
tag is in a shadow root element, but then hardly any general solution will work with shadow roots elements. There you will need a custom approach and expand first the shadow roots.
当然,如果video
标签位于影子根元素中,则上述情况将不起作用,但几乎没有任何通用解决方案适用于影子根元素。在那里您将需要一种自定义方法并首先扩展阴影根。
回答by Harish Varaliya
<video class="embed-responsive-item" controls>
<source src="http://example.com/video.mp4" autostart="false">
Your browser does not support the video tag.
</video>
回答by Reza
You can set autoplay=""
你可以设置 autoplay=""
<video width="640" height="480" controls="controls" type="video/mp4" autoplay="">
<source src="http://example.com/mytestfile.mp4">
Your browser does not support the video tag.
</video>
ps. for enabling you can use autoplay
or autoplay="autoplay"
附:为了使您可以使用autoplay
或autoplay="autoplay"
回答by DemOnyitO
just put the autoplay="false" on source tag.. :)
只需将 autoplay="false" 放在源标签上.. :)