如何停止视频的预加载(HTML5 - Javascript)
我有一个带有视频播放器的网页,预加载了 3 个视频(同一视频的低质量、中质量和高质量)。然后,当用户单击与所需版本相对应的按钮时,视频将打开。
我想做的是停止另外两个视频的预加载。
这可能吗?换句话说,是否可以使用某些 Javascript 来取消或即时停止 HTML5 Video 标记的“预加载”属性?
I have a web page with a video player preloading 3 videos (low, med, and high quality of the same video). Then, when the user clicks on one the button corresponding to the desired version, the video opens.
What I would like to do is to then stop the preloading of the two other videos.
Is that possible? In other words, can the "preload" attribute of the HTML5 Video tag be cancelled or stopped on the fly with some Javascript ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 jQuery,您可以尝试:
我不知道它会停止已经预加载的视频。
从 UI 角度来看,为什么要尝试同时预加载所有 3 个视频?这会减慢所有三个的加载速度;如果您只预加载其中之一,则更多视频将有机会在用户开始观看之前进行缓冲。
我建议预加载默认质量的视频之一,并且仅在用户选择时才加载不同质量的视频。这是 YouTube、Netflix 和其他公司使用的行为。
With jQuery, you can try:
I don't know that it will stop a video that's already preloading.
From a UI perspective, why are you trying to preload all 3 videos at the same time? This will slow down the loading speed of all three; if you only preload one of them, more of the video will have a chance to buffer before the user starts viewing it.
I would suggest preloading one of the videos of a default quality and only loading a different quality video if the user selects it. This is the behaviour used by YouTube, Netflix, and others.
现在有专门的标签:
There is dedicated tag nowadays:
我刚刚想出了一个解决方案来解决我遇到的与您类似的问题。我正在页面上预加载一系列电影列表,但我需要能够跳转到其中一个电影,并将其优先于可能已经预加载的电影,以便尽快播放。
我有一个 div#prebuffer 元素,用于保存预加载的视频,因为它们是缓冲的。当我需要忘记预加载时,我只需这样做:
它有点难看,但我无法找到更好的方法。它完成了工作。
I just came up with a solution to a problem I had that resembles your own. I am preloading a list of movies on my page, in series, but I need to be able to jump to one of them and prioritize it ahead of whatever might have already been preloading, in order to play it as quickly as possible.
I have a div#prebuffer element that holds the preloaded videos, as they are buffered. When I need to forget about preloading, I simply do this:
It's slightly ugly, but I wasn't able to find a nicer way. And it gets the job done.