How do I stop my mediaelement.js player from downloading when it is paused/stopped?

那年仲夏 提交于 2019-12-11 07:35:50

问题


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.


回答1:


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.




回答2:


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 ]




回答3:


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.



来源:https://stackoverflow.com/questions/5130017/how-do-i-stop-my-mediaelement-js-player-from-downloading-when-it-is-paused-stopp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!