videojs / videojs-contrib-quality-levels

Other
154 stars 52 forks source link

The simplest of questions: how do you change the quality? #150

Open Florinstruct opened 5 months ago

Florinstruct commented 5 months ago

Description

I can't for the life of me find any info on how to actually change the quality. The following part from your documentation makes me think this is outside the scope of this plugin?!

When your playback plugin changes the selected quality for playback...

Now, your documentation also says we need videojs/http-streaming and they write:

See the videojs-contrib-quality-levels project page for more information on how to use the api.

So, which is it now? Does this plugin provide an API or does videojs itself?

Steps

I'm using this snippet from your page:

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

But this does nothing. Apparently, it's really just there to "update the QualityLevelList.selectedIndex_" - for whatever reason I would want to / have to do that myself.

If I am misunderstanding the README, there seem to be others. Maybe the documentation is just not clear?

metal450 commented 2 months ago

Did you ever figure this out? I can't get it working either. Seems like incredibly unclear docs to me.

kennethstarkrl commented 1 month ago
const player = (playerRef.current = videojs(videoElement, options, () => {
    player.on('loadedmetadata', () => {
      const qualityLevels = player.qualityLevels();
      qualityLevels.on('change', function() {
        console.log('Quality Level changed!');
        console.log('New level:', qualityLevels[qualityLevels.selectedIndex]);
        const currentTime = player.currentTime();
        player.src(options.sources[qualityLevels.selectedIndex]); //<--- change the source
        player.currentTime(currentTime); // <-- set the new source to the previous source current seek position
        player.play();
      });
    });
}));