Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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 ]

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top