From 0094ef9f15718730a2823e93a2034cad12677405 Mon Sep 17 00:00:00 2001
From: FireMasterK <20838718+FireMasterK@users.noreply.github.com>
Date: Tue, 22 Jun 2021 01:33:11 +0530
Subject: [PATCH] Implement default quality preference.
---
src/components/Player.vue | 27 ++++++++++++++++++++++++++-
src/components/Preferences.vue | 18 ++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/src/components/Player.vue b/src/components/Player.vue
index 92d458e0..6dbf3ab7 100644
--- a/src/components/Player.vue
+++ b/src/components/Player.vue
@@ -1,7 +1,12 @@
@@ -134,7 +139,27 @@ export default {
)
this.player.configure("manifest.disableVideo", true);
+ const quality = Number(localStorage.getItem("quality"));
+ const qualityConds = quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream);
+ if (qualityConds) this.player.configure("abr.enabled", false);
+
player.load(uri, 0, uri.indexOf("dash+xml") >= 0 ? "application/dash+xml" : "video/mp4").then(() => {
+ if (qualityConds) {
+ var leastDiff = Number.MAX_VALUE;
+ var bestStream = null;
+ player
+ .getVariantTracks()
+ .sort((a, b) => a.bandwidth - b.bandwidth)
+ .forEach(stream => {
+ const diff = Math.abs(quality - stream.height);
+ if (diff < leastDiff) {
+ leastDiff = diff;
+ bestStream = stream;
+ }
+ });
+ player.selectVariantTrack(bestStream);
+ }
+
this.video.subtitles.map(subtitle => {
player.addTextTrackAsync(
subtitle.url,
diff --git a/src/components/Preferences.vue b/src/components/Preferences.vue
index 08a4642d..cf84749d 100644
--- a/src/components/Preferences.vue
+++ b/src/components/Preferences.vue
@@ -38,6 +38,21 @@
Audio Only
+
+ Default Quality
+
+
Instances List
@@ -85,6 +100,7 @@ export default {
skipMusicOffTopic: true,
autoPlayVideo: true,
audioOnly: false,
+ defaultQuality: 0,
};
},
mounted() {
@@ -147,6 +163,7 @@ export default {
this.autoPlayVideo =
localStorage.getItem("playerAutoPlay") === null || localStorage.getItem("playerAutoPlay") === "true";
this.audioOnly = localStorage.getItem("audioOnly") === "true";
+ this.defaultQuality = Number(localStorage.getItem("quality"));
}
},
methods: {
@@ -166,6 +183,7 @@ export default {
localStorage.setItem("playerAutoPlay", this.autoPlayVideo);
localStorage.setItem("audioOnly", this.audioOnly);
+ localStorage.setItem("quality", this.defaultQuality);
}
},
sslScore(url) {