Search code examples
http-live-streaminghls.js

How to Stop HLS.js Video Preloading?


I have tried adding the preload attribute with a value of none to the video tag but it doesn’t stop the hls.js Library from preloading from the video.

How can one stop preloading of hls.js videos?


Solution

  • If you do not want to preload the video, do the following:

    1. add autoStartLoad with a value of false when creating the HLS config like this: new Hls({ autoStartLoad: false })
    2. Add a play event listener to the native HTML video element, call hls.startLoad(), and then remove that event listener to avoid calling startLoad multiple times since it only needs to be called once

    For browsers that play hls videos natively, you can just add the preload attribute with a value of false to the native HTML video element