From 78a1655dd8cb3d5a8828a6c8d1ba3ecd0e76800d Mon Sep 17 00:00:00 2001 From: Preston Date: Mon, 21 Sep 2020 18:39:25 -0400 Subject: [PATCH] Prevent next video from playing if user leaves page --- src/renderer/views/Watch/Watch.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index 662b3039..e5d4039d 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -65,7 +65,8 @@ export default Vue.extend({ captionSourceList: [], recommendedVideos: [], watchingPlaylist: false, - playlistId: '' + playlistId: '', + playNextTimeout: null } }, computed: { @@ -594,7 +595,7 @@ export default Vue.extend({ handleVideoEnded: function () { if (this.watchingPlaylist) { - const timeout = setTimeout(() => { + this.playNextTimeout = setTimeout(() => { this.$refs.watchVideoPlaylist.playNextVideo() }, 5000) @@ -602,14 +603,14 @@ export default Vue.extend({ message: this.$t('Playing next video in 5 seconds. Click to cancel'), time: 5500, action: () => { - clearTimeout(timeout) + clearTimeout(this.playNextTimeout) this.showToast({ message: this.$t('Canceled next video autoplay') }) } }) } else if (this.playNextVideo) { - const timeout = setTimeout(() => { + this.playNextTimeout = setTimeout(() => { const nextVideoId = this.recommendedVideos[0].videoId this.$router.push( { @@ -625,7 +626,7 @@ export default Vue.extend({ message: this.$t('Playing next video in 5 seconds. Click to cancel'), time: 5500, action: () => { - clearTimeout(timeout) + clearTimeout(this.playNextTimeout) this.showToast({ message: this.$t('Canceled next video autoplay') }) @@ -635,6 +636,8 @@ export default Vue.extend({ }, handleRouteChange: function () { + clearTimeout(this.playNextTimeout) + if (this.rememberHistory && !this.isLoading && !this.isLive) { const player = this.$refs.videoPlayer.player