Hls.js: Can't set Level on load

Created on 3 Jun 2016  Â·  10Comments  Â·  Source: video-dev/hls.js

I need to disable autoLevel and set certain Level before video playing starts.

Here is my code:

 var video = document.getElementById('video');
    if(Hls.isSupported()) {
        var hls = new Hls();
        // bind them together
        hls.attachMedia(video);
        hls.on(Hls.Events.MEDIA_ATTACHED,function() {
            hls.loadSource("http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8");
            hls.on(Hls.Events.MANIFEST_PARSED, function(event,data) {
                hls.autoLevelEnabled = false;
                hls.currentLevel = 3;
                video.play();
            })
        });
    }

Nothing happens when page loaded (just blank video place). If I set hls.currentLevel = 3 after video.play(), two simillar errors in console apperar:

undefined:1 Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().
undefined:1 Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

I can set Level after video playing starts, however it'd be nice if I can set it before.

Question

All 10 comments

you can eventually try to use
var hls = new Hls({autoStartLoad : false});

then set hls.loadLevel = 3; instead

Changed the code:

    var video = document.getElementById('video');
    if(Hls.isSupported()) {
        var hls = new Hls({autoStartLoad : false});
        // bind them together
        hls.attachMedia(video);
        hls.on(Hls.Events.MEDIA_ATTACHED,function() {
            hls.loadSource("http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8");
            hls.on(Hls.Events.MANIFEST_PARSED, function(event,data) {
                hls.autoLevelEnabled = false;
                hls.loadLevel = 3;
                video.play();
            })
        });
    }

Now video doesn't start at all.

you need to call hls.startLoad() in MANIFEST_PARSED

Yep, this works! Thank you.

Is autoLevelEnabled also a setter? - The doc's phrasing suggests it's a getter only: 'tell whether auto level selection is enabled or not'.

@blacktrash
hls.autoLevelEnabled = false; I think this code will do nothing
if you want to enable auto level, you can set currentLevel, nextLevel or loadLevel to -1

@chjcken - yes, that's what I'm thinking too, that's why I asked for confirmation ;-)

issue -
My video with hls on 0 level play but when be load or set another level video is stop this issue comes only with below type of video url

https://cdn.grapevine.work/grapevine.work/1408897/VID-25012021_16_26_27.m3u8
code : hlslevelevelissue.zip

pls help
hlslevelevelissue.zip

issue -
My video with hls on 0 level play but when be load or set another level video is stop this issue comes only with below type of video url

https://cdn.grapevine.work/grapevine.work/1408897/VID-25012021_16_26_27.m3u8
code : hlslevelevelissue.zip

pls help
hlslevelevelissue.zip

Screenshot_2021-01-30-16-46-49-176_com.android.chrome.jpg

in my player with hls.js v0.12.4 your m3u8 run smoothly in startlevel 0 and startlevel 1

pls check with this video url

https://cdn.grapevine.work/grapevine.work/1357851/VID-14012021_14_36.m3u8

this hls video url not play other level .play only 0 level out of 3level

On Sat, Jan 30, 2021 at 3:21 PM dio notifications@github.com wrote:

issue -
My video with hls on 0 level play but when be load or set another level
video is stop this issue comes only with below type of video url

https://cdn.grapevine.work/grapevine.work/1408897/VID-25012021_16_26_27.m3u8
code : hlslevelevelissue.zip

pls help
hlslevelevelissue.zip
https://github.com/video-dev/hls.js/files/5897545/hlslevelevelissue.zip

[image: Screenshot_2021-01-30-16-46-49-176_com.android.chrome.jpg]
https://user-images.githubusercontent.com/80703/106353187-4bafa080-631b-11eb-9aaa-93d5464eb0a3.jpg

in my player with hls.js v0.12.4 your m3u8 run smoothly in startlevel 0
and startlevel 1

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/video-dev/hls.js/issues/478#issuecomment-770186021,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ASU7KJHKUZJA7ILMXARXHZLS4PJDBANCNFSM4CFVJD7A
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itsjamie picture itsjamie  Â·  3Comments

dan-ziv picture dan-ziv  Â·  4Comments

mmmmoj picture mmmmoj  Â·  3Comments

phillydogg28 picture phillydogg28  Â·  4Comments

shalommeoded picture shalommeoded  Â·  3Comments