Html 如何防止 html5 视频在播放前加载?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14300141/
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
How to prevent html5 video from loading before playing?
提问by Will Ryan
I have several html5 videos on one page and I've just realized that when you visit the page, all the videos start loading even though I haven't clicked play on any of them.
我在一个页面上有几个 html5 视频,我刚刚意识到当您访问该页面时,所有视频都开始加载,即使我没有点击其中任何一个播放。
Is there a way to only load a video once you click play, to prevent unnecessary downloading?
有没有办法只在点击播放后加载视频,以防止不必要的下载?
回答by Timothy Radzikowski
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls="controls" preload="none">
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
</body>
</html>
Use Preload"none"
使用预加载“无”
回答by Gabriele Petrioli
You should use the preload
attribute, and set its value to none
.
您应该使用该preload
属性,并将其值设置为none
。
Quote from the <video>
specification
从报价的<video>
规范
preload
= "none" or "metadata" or "auto" or "" (empty string) or empty
Represents a hint to the UA about whether optimistic downloading of the video itself or its metadata is considered worthwhile.
- "none": Hints to the UA that the user is not expected to need the video, or that minimizing unnecessary traffic is desirable.
preload
=“ none”或“ metadata”或“ auto”或“”(空字符串)或空
表示向UA提示关于视频本身或其元数据的乐观下载是否值得。
- “ none”:向 UA 提示用户不需要视频,或者需要最小化不必要的流量。
回答by Harikrishna
Just use <video preload="none">
只需使用 <video preload="none">
And if you want to load meta data only of video then use <video preload="metadata">
如果您只想加载视频的元数据,请使用 <video preload="metadata">