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

Does not handle removequalitylevel event #101

Open
stevendesu opened this issue Sep 10, 2019 · 0 comments
Open

Does not handle removequalitylevel event #101

stevendesu opened this issue Sep 10, 2019 · 0 comments

Comments

@stevendesu
Copy link

For various reasons someone may wish to remove quality levels in a VideoJS plugin:

  • Limiting access to 1080p to paid subscribers
  • Removing a quality level if a TS file 404's to avoid automatically switching back to it in the future
  • Selecting only the profiles that are supported on a particular device if you have 540p-main and 540p-baseline
  • etc

Currently the following code will lead to errors:

var player = videojs("my_player");
player.qualityLevels().removeQualityLevel(player.qualityLevels()[0]);

When this happens, the _toggleLevel method throws an error because this[i] is undefined. Looking into it a bit, it seems like removing any quality level other than the last one shifts the index of all other levels. So after removing quality level 0, the former "quality level 1" will become the new "quality level 0", the former "quality level 2" will become the new "quality level 1", etc - and "quality level X" (the last one in the list) will be "undefined"

However the _toggleLevel method is bound with a particular quality level's ID. This means that the wrong quality level is accessed after one has been removed

It should be possible to work around this by scanning the list for the appropriate level each time. For instance:

var selectedLevel = null;
for (var i = 0; i < this.length; i++) {
    if (this[i].id === level) {
        selectedLevel = this[i];
        break;
    }
}
if (selectedLevel) {
    if (typeof toggle === "boolean") {
        selectedLevel._enabled = toggle;
        _relayQualityChange(this);
    }
    return selectedLevel._enabled;
}
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

1 participant