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 2020-12-19 17:48:20 +01:00
rodzic eea7ca9b72
commit eed78c960d
2 zmienionych plików z 20 dodań i 3 usunięć

Wyświetl plik

@ -159,9 +159,26 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
player.ready(() => {
player.on("loadedmetadata", () => {
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++) {
qualityLevels[i].enabled = (i == targetQualityLevel)
qualityLevels[i].enabled = (i == targetQualityLevel);
}
});
});

Wyświetl plik

@ -61,7 +61,7 @@
<div class="pure-control-group">
<label for="quality_dash"><%= translate(locale, "Preferred dash video quality: ") %></label>
<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>
<% end %>
</select>