最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I stop the preload of a video (HTML5 - Javascript) - Stack Overflow

programmeradmin4浏览0评论

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 ?

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 ?

Share Improve this question asked Aug 2, 2010 at 12:37 mike23mike23 1,3226 gold badges21 silver badges32 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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:

var $video = $('#prebuffer video:last');
$video.find('source').attr('src', '');
$video[0].load();
// it has now stopped preloading.
// and then, because I don't want this half-loaded broken cruft hanging around:
$video.remove();

It's slightly ugly, but I wasn't able to find a nicer way. And it gets the job done.

With jQuery, you can try:

$('#videoPlayerId').removeAttr('preload');

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:

<video preload="none" ....>
发布评论

评论列表(0)

  1. 暂无评论