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;
}
For various reasons someone may wish to remove quality levels in a VideoJS plugin:
540p-mainand540p-baselineCurrently the following code will lead to errors:
When this happens, the
_toggleLevelmethod throws an error becausethis[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
_toggleLevelmethod is bound with a particular quality level's ID. This means that the wrong quality level is accessed after one has been removedIt should be possible to work around this by scanning the list for the appropriate level each time. For instance: