当 mediaelement.js 播放器暂停/停止时,如何阻止其下载?

发布于 2024-10-19 04:09:04 字数 208 浏览 3 评论 0原文

我的网站上有一个视频播放器,一旦暂停,我想阻止下载视频的其余部分。我正在使用 MediaElement.js 用于具有 Flash 回退功能的 html5 视频。令人烦恼的是,我无法阻止视频下载,因为这浪费了带宽,并且“进度”事件继续触发并更新用户界面。

I have a video player on my site that once paused I would like to prevent rest of the video being downloaded. I am using MediaElement.js for html5 video with flash fallback. It is annoying that I am unable to stop the video from downloading as it is a waste of bandwidth and the "progress" event continues to fire and update the UI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明媚如初 2024-10-26 04:09:04

不幸的是,没有办法告诉浏览器停止下载视频文件,然后在同一点恢复下载。如果能包含在 HTML5 规范中就好了,但事实并非如此。

您可以尝试使用“暂停”将播放器的 .src 设置为“”,然后当“播放”事件触发时,您可以将 src 设置回 URL。但我的猜测是你会丢失已经下载的内容。

Unfortunately, there is no way to tell browsers to stop downloading a video file and then resume it later at the same point. It'd be nice it that were in the HTML5 spec, but it's not.

You could try hacking around using the 'paused' to set the .src of the player to '', and then when the 'play' event fires, you could set the src back to the URL. But my guess is that you'd lose what was already downloaded.

鼻尖触碰 2024-10-26 04:09:04

我自己就遇到了这个问题,在阅读了这里的其他问答并测试了清除数组之后,最简单的方法就是更改源属性以有效地中断下载。

已在 mac 上的 chrome/FF/Safari 和 PC 上的 IE[7,8,9]/FF/Chrome 中进行测试,运行良好。

[抱歉,试图将其添加到约翰的答案中作为确认,但显然这比解决这个问题更棘手:p]

Just ran in to this problem myself and after reading other Q&A on here and testing clearing arrays and what not it is simplest just to change the source attribute to effectively break the download.

Have tested it in chrome/FF/Safari on mac and IE[7,8,9]/FF/Chrome on PC and it works fine.

[sorry tried to add this to John's answer as confirm but apparently that's trickier than hacking this problem :p ]

美人迟暮 2024-10-26 04:09:04

我想为戴尔的答案添加一个附录。

1.) 您可以停止下载视频,但仅限于从页面中删除视频的目的。在使用 MediaElement 的 .remove() 之前,请清除 VIDEO 标记的 src。这将初始化浏览器的垃圾收集并停止下载视频。

$('video').attr('src','');

2.) 默认情况下,浏览器启用缓存,普通用户不会更改它。大多数开发人员在工作时都禁用了缓存。如果您的缓存已启用:

IE8 (Flash) - 将在视频完全下载后对其进行缓存。
IE9 (HTML5) -- 将恢复部分视频和视频的下载缓存。
FF (HTML5) -- 完全下载后将缓存视频。
Chrome (HTML5)——不会缓存视频。每次都会重新下载视频。

I'd add an addendum to Dyer's answer.

1.) You can stop the video from downloading, but only for the purpose of removing the video from the page. Before using MediaElement's .remove(), clear the VIDEO tag's src. This will initialize the browser's garbage collection and stop the video from downloading.

$('video').attr('src','');

2.) By default, browsers have their cache enabled and normal users won't change it. Most developers have caching disabled when they're working. If your cache is enabled:

IE8 (Flash) -- Will cache the video once it has fully downloaded.
IE9 (HTML5) -- Will resume downloading of partial videos & cache.
FF (HTML5) -- Will cache the video once it has fully downloaded.
Chrome (HTML5) -- Will NOT cache the videos. It will re-download videos every time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文