Hold playback until initial buffer length
What do you want to do with Hls.js?
Is it possible to adjust the initial buffer length to start the video? We have the first two chanks that are 2 seconds long, and sometimes there is a problem on a weak network that the video starts, but there is not enough buffer, and after 4 seconds of playback, a loader appears. would like to wait a little longer at the first download, but not get a playback freeze.
What have you tried so far?
No response
How or when do you call play() on the video? Wait until the buffer is full.
Basically, we have a subscription to the canplay event of the video tag. Yes, we can check the buffer on our side, I was just wondering if there is such a setting in HLS.js
Basically, we have a subscription to the canplay event of the video tag. Yes, we can check the buffer on our side, I was just wondering if there is such a setting in HLS.js
There is not. Rather than depending on HTMLMediaElement "canplay" event, you can use BUFFER_APPENDED, BUFFER_EOS, or FRAG_BUFFERED. BUFFER_APPENDED is probably the most appropriate and informative. You'd still check the HTMLMediaElement.buffered ranges compared the HTMLMediaElement.currentTime. BUFFER_EOS would signal that there are no more segments to load (so just play() already).
I think if we were to make an enhancement, since we do not want HLS.js to manage playback state, what we would do instead it force queuing of appends until more than X amount is accumulated. This could be anywhere from 0-10 seconds with 0 being current behavior and "10" (or some other upper bound) being a value we feel should be safe to avoid OOM errors for most variants. This way all media needed to start would be appended to MSE in rapid succession from memory. Playback could not start until this safe amount was accumulated in the append queue.
See buffer-controller for how the append queue operates. There is already some code to prevent audio from appending until video is ready.
Thanks for the detailed answer. I will look at the buffer-controller and try to make these changes.