Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify default quality #113

Open
metal450 opened this issue Jun 29, 2024 · 3 comments
Open

Specify default quality #113

metal450 opened this issue Jun 29, 2024 · 3 comments

Comments

@metal450
Copy link

Is there a way to specify the default/initial quality that will be selected when the player first comes up? It seems there's no such option in the constructor, & I tried to figure out how to do it programmatically, both via this plugin directly and via videojs-contrib-quality-levels, but couldn't get it working. i.e.

// ...
var qualities = player.qualityLevels();
var qualitySelector = player.hlsQualitySelector({displayCurrentQuality:true});

qualities.on('addqualitylevel', () =>{
              if(qualities.length === 1) {
                console.log("Manually setting stream");
                qualitySelector.setQuality(360);
              }
            });

qualities.on('change', ()=> {
              console.log(`Stream changed to: ${qualities[qualities.selectedIndex].id}`);
            });
// ...

This updated the displayed selection on the UI, but didn't actually change the stream (i.e. the display showed 360p, but it was still playing a different quality). Same if I pass '360' (as a string) '360p', or 1 (the index).

I also tried directly setting it in qualityLevels plugin, but nothing seemed to work, i.e.:

qualityLevels.selectedIndex_ = 1;
qualityLevels.trigger({ type: 'change', selectedIndex: 1 });

Thanks in advance

@PauloMendees
Copy link

I'm also interested, do you find the solution?

@metal450
Copy link
Author

            const requestedQuality = parseInt(new URLSearchParams(window.location.search).get('quality'))
            if(requestedQuality) {

              var requestedQualityWasFound = false
              qualities.on('addqualitylevel', () => {

                // Don't do anything until actually load a stream that matches the requested quality
                var q = qualities[qualities.length - 1]
                if (q.height === requestedQuality) {
                  console.log(`Requested quality found; changing stream to: "${q.label}"`)
                  requestedQualityWasFound = true
                }
                if (!requestedQualityWasFound)
                  return

                // Once we find the requested quality, set it. Note: Intentionally continuing to call this
                // for all qualities that are loaded after the one that was requested - doesn't work otherwise!
                qualitySelector.setQuality(requestedQuality);
              })
            }

@PauloMendees
Copy link

Thats odd, didn't work here. But thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants