Prevent HTML5 videos from downloading the files on mobile - videojs

前端 未结 3 1394
一个人的身影
一个人的身影 2021-02-02 10:56

So I\'m currently building a website that has a carousel containing four videos, each video is triggered to play by hooking in to the Bootstrap 3 carousel\'s slide.bs.caro

3条回答
  •  误落风尘
    2021-02-02 11:37

    Based on the suggestions Ian kindly made, here is my working solution.

    Firstly, I changed each video's child source elements to have an attribute data-src like so:

    
    

    Then, after performing a mobile check using the script available at http://detectmobilebrowsers.com/ which I modified to include iPads etc (related SO answer here) I simply used the following script to automatically update the src attribute of each video (if we're on desktop in my case):

    var sources = document.querySelectorAll('video#my-id source');
    // Define the video object this source is contained inside
    var video = document.querySelector('video#my-id');
    for(var i = 0; i

    And that's it! Nothing loads on mobile devices anymore and I can have fairly granular control over the devices it will or won't load on.

    Hope this helps somebody.

提交回复
热议问题