From e696af3f7ad244158a1986ed49e1a6abf0226b76 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Thu, 29 Apr 2021 19:33:13 +0100 Subject: [PATCH] Apply playlist autoplay interval to regular autoplay The interval to play the next video in a playlist was dynamic and wasn't applied to the normal autoplay timer. This commit merges the logic of these two scenarios so that they both utilize the user-defined interval. --- .../player-settings/player-settings.vue | 2 +- src/renderer/views/Watch/Watch.js | 82 ++++++++----------- static/locales/en-US.yaml | 2 +- 3 files changed, 36 insertions(+), 50 deletions(-) diff --git a/src/renderer/components/player-settings/player-settings.vue b/src/renderer/components/player-settings/player-settings.vue index 001b9486..371eff7c 100644 --- a/src/renderer/components/player-settings/player-settings.vue +++ b/src/renderer/components/player-settings/player-settings.vue @@ -62,7 +62,7 @@ { - const player = this.$refs.videoPlayer.player - if (player !== null && player.paused()) { + this.playNextTimeout = setTimeout(() => { + const player = this.$refs.videoPlayer.player + if (player !== null && player.paused()) { + if (this.watchingPlaylist) { this.$refs.watchVideoPlaylist.playNextVideo() - } - }, nextVideoInterval * 1000) - - let countDownTimeLeftInSecond = nextVideoInterval - const showCountDownMessage = () => { - // Will not display "Playing next video in no time" as it's too late to cancel - // Also there is a separate message when playing next video - if (countDownTimeLeftInSecond <= 0) { - clearInterval(countDownIntervalId) - return - } - - this.showToast({ - message: this.$tc('Playing Next Video Interval', countDownTimeLeftInSecond, { nextVideoInterval: countDownTimeLeftInSecond }), - // To avoid message flashing - // `time` is manually tested to be 700 - time: 700, - action: () => { - clearTimeout(this.playNextTimeout) - clearInterval(countDownIntervalId) - this.showToast({ - message: this.$t('Canceled next video autoplay') - }) - } - }) - - // At least this var should be updated AFTER showing the message - countDownTimeLeftInSecond = countDownTimeLeftInSecond - 1 - } - // Execute once before scheduling it - showCountDownMessage() - const countDownIntervalId = setInterval(showCountDownMessage, 1000) - } else if (this.playNextVideo) { - this.playNextTimeout = setTimeout(() => { - const player = this.$refs.videoPlayer.player - if (player !== null && player.paused()) { + } else { const nextVideoId = this.recommendedVideos[0].videoId - this.$router.push( - { - path: `/watch/${nextVideoId}` - } - ) + this.$router.push({ + path: `/watch/${nextVideoId}` + }) this.showToast({ message: this.$t('Playing Next Video') }) } - }, 5000) + } + }, nextVideoInterval * 1000) + + let countDownTimeLeftInSecond = nextVideoInterval + const showCountDownMessage = () => { + // Will not display "Playing next video in no time" as it's too late to cancel + // Also there is a separate message when playing next video + if (countDownTimeLeftInSecond <= 0) { + clearInterval(countDownIntervalId) + return + } this.showToast({ - message: this.$t('Playing next video in 5 seconds. Click to cancel'), - time: 5500, + message: this.$tc('Playing Next Video Interval', countDownTimeLeftInSecond, { nextVideoInterval: countDownTimeLeftInSecond }), + // To avoid message flashing + // `time` is manually tested to be 700 + time: 700, action: () => { clearTimeout(this.playNextTimeout) + clearInterval(countDownIntervalId) this.showToast({ message: this.$t('Canceled next video autoplay') }) } }) + + // At least this var should be updated AFTER showing the message + countDownTimeLeftInSecond = countDownTimeLeftInSecond - 1 } + // Execute once before scheduling it + showCountDownMessage() + const countDownIntervalId = setInterval(showCountDownMessage, 1000) }, handleRouteChange: function () { diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 075f4ee2..30199a42 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -171,7 +171,7 @@ Settings: Proxy Videos Through Invidious: Proxy Videos Through Invidious Autoplay Playlists: Autoplay Playlists Enable Theatre Mode by Default: Enable Theatre Mode by Default - Playlist Next Video Interval: Playlist Next Video Interval + Next Video Interval: Next Video Interval Default Volume: Default Volume Default Playback Rate: Default Playback Rate Default Video Format: