From 2a1982b0ddb82ed59d72aaf2efd823e567d7f702 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 5 Jun 2023 20:25:13 +0530 Subject: [PATCH] Fixed a race condition between loading data and start time calculation, fixed start time setting when player.load is ignored --- src/components/Player.vue | 4 +++- src/routes/WatchVideo.vue | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index dab1942..d39856a 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -342,6 +342,9 @@ export default { this.setupSeekbarPreview() this.$player = player + const startTime = this.initialSkip != null && Number.isFinite(this.initialSkip) ? this.initialSkip : 0 + this.skipToTime(startTime) + this.$player.configure({ preferredVideoCodecs: this.preferredVideoCodecs, preferredAudioCodecs: ['opus', 'mp4a'], @@ -357,7 +360,6 @@ export default { const qualityConds = quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !this.audioOnly if (qualityConds) this.$player.configure('abr.enabled', false) - const startTime = this.initialSkip != null && Number.isFinite(this.initialSkip) ? this.initialSkip : 0 player.load(uri, startTime, mime).then(() => { let bestFitLanguage { diff --git a/src/routes/WatchVideo.vue b/src/routes/WatchVideo.vue index 9bcf29f..981ea11 100644 --- a/src/routes/WatchVideo.vue +++ b/src/routes/WatchVideo.vue @@ -368,20 +368,6 @@ export default { video.videoId = this.videoId video.url = this.$route.fullPath - this.video = video - this.loaded = true - - if (this.video.error) { - return - } - this.channelId = this.video.uploaderUrl.split('/')[2] - - this.video.description = LibPiped.purifyHTML( - this.video.description - .replaceAll('http://www.youtube.com', '') - .replaceAll('https://www.youtube.com', '') - .replaceAll('\n', '
') - ) try { if (!this.$store.getters['prefs/getPreference']('disableDuplicateHistoryEntries', false)) { this.dbID = await addWatchedVideo(video) @@ -409,6 +395,21 @@ export default { } catch (e) { console.error('Errored while finding last watched', e) } + + this.video = video + this.loaded = true + + if (this.video.error) { + return + } + this.channelId = this.video.uploaderUrl.split('/')[2] + + this.video.description = LibPiped.purifyHTML( + this.video.description + .replaceAll('http://www.youtube.com', '') + .replaceAll('https://www.youtube.com', '') + .replaceAll('\n', '
') + ) }, onTimeUpdate: throttle(function onTimeUpdate () {