From 3a5fe4780bcf7fb87c46075b811ade6abbec8346 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Tue, 29 Aug 2023 17:07:30 +0000 Subject: [PATCH 1/2] display error in player --- src/components/VideoPlayer.vue | 136 ++++++++++++++++++--------------- src/locales/en.json | 3 +- 2 files changed, 76 insertions(+), 63 deletions(-) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index 8ff5be5b..b419488c 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -25,6 +25,11 @@ skip_next + @@ -67,6 +72,7 @@ export default { isHoveringTimebar: false, currentTime: 0, seekbarPadding: 2, + error: 0, }; }, computed: { @@ -517,73 +523,79 @@ export default { quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !disableVideo; if (qualityConds) this.$player.configure("abr.enabled", false); - player.load(uri, 0, mime).then(() => { - const isSafari = window.navigator?.vendor?.includes("Apple"); + player + .load(uri, 0, mime) + .then(() => { + const isSafari = window.navigator?.vendor?.includes("Apple"); - if (!isSafari) { - // Set the audio language - const prefLang = this.getPreferenceString("hl", "en").substr(0, 2); - var lang = "en"; - for (var l in player.getAudioLanguages()) { - if (l == prefLang) { - lang = l; - return; - } - } - player.selectAudioLanguage(lang); - } - - if (qualityConds) { - var leastDiff = Number.MAX_VALUE; - var bestStream = null; - - var bestAudio = 0; - - const tracks = player - .getVariantTracks() - .filter(track => track.language == lang || track.language == "und"); - - // Choose the best audio stream - if (quality >= 480) - tracks.forEach(track => { - const audioBandwidth = track.audioBandwidth; - if (audioBandwidth > bestAudio) bestAudio = audioBandwidth; - }); - - // Find best matching stream based on resolution and bitrate - tracks - .sort((a, b) => a.bandwidth - b.bandwidth) - .forEach(stream => { - if (stream.audioBandwidth < bestAudio) return; - - const diff = Math.abs(quality - stream.height); - if (diff < leastDiff) { - leastDiff = diff; - bestStream = stream; + if (!isSafari) { + // Set the audio language + const prefLang = this.getPreferenceString("hl", "en").substr(0, 2); + var lang = "en"; + for (var l in player.getAudioLanguages()) { + if (l == prefLang) { + lang = l; + return; } - }); + } + player.selectAudioLanguage(lang); + } - player.selectVariantTrack(bestStream); - } + if (qualityConds) { + var leastDiff = Number.MAX_VALUE; + var bestStream = null; - this.video.subtitles.map(subtitle => { - player.addTextTrackAsync( - subtitle.url, - subtitle.code, - "subtitles", - subtitle.mimeType, - null, - subtitle.name, - ); + var bestAudio = 0; + + const tracks = player + .getVariantTracks() + .filter(track => track.language == lang || track.language == "und"); + + // Choose the best audio stream + if (quality >= 480) + tracks.forEach(track => { + const audioBandwidth = track.audioBandwidth; + if (audioBandwidth > bestAudio) bestAudio = audioBandwidth; + }); + + // Find best matching stream based on resolution and bitrate + tracks + .sort((a, b) => a.bandwidth - b.bandwidth) + .forEach(stream => { + if (stream.audioBandwidth < bestAudio) return; + + 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, + subtitle.code, + "subtitles", + subtitle.mimeType, + null, + subtitle.name, + ); + }); + videoEl.volume = this.getPreferenceNumber("volume", 1); + const rate = this.getPreferenceNumber("rate", 1); + videoEl.playbackRate = rate; + videoEl.defaultPlaybackRate = rate; + + const autoDisplayCaptions = this.getPreferenceBoolean("autoDisplayCaptions", false); + this.$player.setTextTrackVisibility(autoDisplayCaptions); + }) + .catch(e => { + console.error(e); + this.error = e.code; }); - videoEl.volume = this.getPreferenceNumber("volume", 1); - const rate = this.getPreferenceNumber("rate", 1); - videoEl.playbackRate = rate; - videoEl.defaultPlaybackRate = rate; - - const autoDisplayCaptions = this.getPreferenceBoolean("autoDisplayCaptions", false); - this.$player.setTextTrackVisibility(autoDisplayCaptions); - }); // expand the player to fullscreen when the fullscreen query equals true if (this.$route.query.fullscreen === "true" && !this.$ui.getControls().isFullScreenEnabled()) diff --git a/src/locales/en.json b/src/locales/en.json index 1b73aeba..268fa6f9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -18,7 +18,8 @@ "dearrow": "DeArrow" }, "player": { - "watch_on": "Watch on {0}" + "watch_on": "Watch on {0}", + "failed": "Failed with error code {0}, refer logs for more info" }, "actions": { "subscribe": "Subscribe - {count}", From 13d16f83b933befede72f655775f1ca4578dfd7b Mon Sep 17 00:00:00 2001 From: Shiny Nematoda <122038334+snematoda@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:59:11 +0200 Subject: [PATCH 2/2] Be the programmer your linter thinks you are --- src/components/VideoPlayer.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index b419488c..90d326bb 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -28,7 +28,7 @@