Izaias
Izaias

Reputation: 389

Cancel html5 video download

I'm building a video playlist. Everytime the user clicks on a new item, I would like to stop downloading the current video (if it's still in progress) before it start downloading the new video.

Here's the code I could come up with. It partially works, but it doesn't seem that any download is being cancelled when I call the destroyVideo() method. I'm using Chrome's network monitor to check that.

function createVideo(videoObject) {
    var html = '<video id="video" loop><source id="mp4" src="' + video.mp4 + '" type="video/mp4" /><source id="webm" src="' + video.webm + '" type="video/webm" /><source id="ogg" src="'+ video.ogg + '" type="video/ogg" /></video>';

    var videoContainerDiv = $('#videoContainerDiv');    
    videoContainerDiv.append(html);

    var asset = $('#video');
    asset.get(0).load();
}


function destroyVideo() {
    var asset = $('#video');

    var mp4 = $('#mp4');
    mp4.attr('src', '');

    var webm = $('#webm');
    webm.attr('src', '');

    var ogg = $('#ogg');
    ogg.attr('src', '');

    asset.attr('src', '');
    asset.get(0).load();

    var videoContainerDiv = $('#videoContainerDiv');
    videoContainerDiv.empty();
}

My question is: is there a more effective way of doing that, cross-browser?

Help is highly appreciated!

Upvotes: 1

Views: 2310

Answers (1)

user1873471
user1873471

Reputation:

function destroyVideo() {
    var asset = $('#video');
    asset.remove();
}

Upvotes: 1

Related Questions