Improve DASH quality preference

Besides `auto`, `best` and `worst` it is now possible to select a target height.
If the target height is not available the closest lower height is selected.
pull/1572/head
saltycrys 4 years ago
parent eea7ca9b72
commit eed78c960d

@ -159,9 +159,26 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
player.ready(() => { player.ready(() => {
player.on("loadedmetadata", () => { player.on("loadedmetadata", () => {
const qualityLevels = Array.from(player.qualityLevels()).sort((a, b) => a.height - b.height); const qualityLevels = Array.from(player.qualityLevels()).sort((a, b) => a.height - b.height);
const targetQualityLevel = video_data.params.quality_dash == "best" ? qualityLevels.length - 1 : 0; let targetQualityLevel;
switch (video_data.params.quality_dash) {
case "best":
targetQualityLevel = qualityLevels.length - 1;
break;
case "worst":
targetQualityLevel = 0;
break;
default:
const targetHeight = Number.parseInt(video_data.params.quality_dash, 10);
for (let i = 0; i < qualityLevels.length; i++) {
if (qualityLevels[i].height <= targetHeight) {
targetQualityLevel = i;
} else {
break;
}
}
}
for (let i = 0; i < qualityLevels.length; i++) { for (let i = 0; i < qualityLevels.length; i++) {
qualityLevels[i].enabled = (i == targetQualityLevel) qualityLevels[i].enabled = (i == targetQualityLevel);
} }
}); });
}); });

@ -61,7 +61,7 @@
<div class="pure-control-group"> <div class="pure-control-group">
<label for="quality_dash"><%= translate(locale, "Preferred dash video quality: ") %></label> <label for="quality_dash"><%= translate(locale, "Preferred dash video quality: ") %></label>
<select name="quality_dash" id="quality_dash"> <select name="quality_dash" id="quality_dash">
<% {"auto", "best", "worst"}.each do |option| %> <% {"auto", "best", "4320p", "2160p", "1440p", "1080p", "720p", "480p", "360p", "240p", "144p", "worst"}.each do |option| %>
<option value="<%= option %>" <% if preferences.quality_dash == option %> selected <% end %>><%= translate(locale, option) %></option> <option value="<%= option %>" <% if preferences.quality_dash == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %> <% end %>
</select> </select>

Loading…
Cancel
Save