在播放前减少 html5 视频缓冲区 [英] Make an html5 video buffer less before playing
问题描述
当有人点击观看我网站上的视频(Html5 视频标签中的 mp4)时 - 浏览器在显示之前会缓冲很多.这不是必需的 - 视频长度不到半分钟,并且在下载整个视频时只显示了一半.
When someone clicks to watch a video on my site (mp4 in an Html5 video tag) - the browser buffers a lot of it before showing it. This is not needed - the video is less than half a minute long, and has shown only half of it by the time the whole video has been downloaded.
有没有办法告诉浏览器不要缓冲太多?
Is there a way to tell browsers not to buffer so much?
推荐答案
评论中有很多关于这是否可以完成的讨论,所以我将在此处提供特定于媒体源的答案.
There's been a lot of discussion in the comments regarding whether this can be done, so I'll provide a Media Source-specific answer here.
媒体源扩展,或称 MSE,是一种新的(尚未得到广泛支持)一组工具,可帮助您使用 HTML5 视频控制缓冲和流式传输.来自 W3C 摘要:
Media Source Extensions, or MSE, are a new (and not yet widely-supported) set of tools to help you control buffering and streaming with HTML5 videos. From the W3C abstract:
此规范扩展了 HTMLMediaElement 以允许 JavaScript 生成用于播放的媒体流.允许 JavaScript 生成流有助于各种用例,如自适应流和时移实时流.
This specification extends HTMLMediaElement to allow JavaScript to generate media streams for playback. Allowing JavaScript to generate streams facilitates a variety of use cases like adaptive streaming and time shifting live streams.
我会特别向您介绍SourceBuffer 对象strong>,其中包含有关音频和处理视频轨道缓冲.
I'll specifically refer you to the SourceBuffer Object, which has information on how audio & video track buffering is handled.
对 MSE 的支持因浏览器和格式而异(source):
Support for MSE varies by browser and format (source):
- 34+ 桌面版 Chrome(MP4、WEBM)
- Android 34+ 版 Chrome(MP4、WEBM)
- Windows 8.1 (MP4) 上的 IE 11+
- 适用于 Windows Phone 8.1+ (MP4) 的 IE
- Mac 版 Safari(MP4、TS)
用户可以在 about:config ( 来源).一段时间的支持工作正在进行中.
Support for Firefox can be turned on by the user in about:config (source). Support has been in the works for some time.
为了有效地利用这一点,还需要实现更多功能,包括视频文件聚类.我建议阅读这个 4 部分系列逐步了解如何利用上述所有内容创建功能齐全的 HTML5 视频播放器.
There is much more that needs to be implemented in order to make use of this effectively, including video file clustering. I would recommend reading this 4-part series that goes step by step into how to create a fully functional HTML5 video player utilizing everything mentioned above.
这篇关于在播放前减少 html5 视频缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!