Prevent next video from playing if user leaves page

This commit is contained in:
Preston 2020-09-21 18:39:25 -04:00
parent d029c6161b
commit 78a1655dd8
1 changed files with 8 additions and 5 deletions

View File

@ -65,7 +65,8 @@ export default Vue.extend({
captionSourceList: [], captionSourceList: [],
recommendedVideos: [], recommendedVideos: [],
watchingPlaylist: false, watchingPlaylist: false,
playlistId: '' playlistId: '',
playNextTimeout: null
} }
}, },
computed: { computed: {
@ -594,7 +595,7 @@ export default Vue.extend({
handleVideoEnded: function () { handleVideoEnded: function () {
if (this.watchingPlaylist) { if (this.watchingPlaylist) {
const timeout = setTimeout(() => { this.playNextTimeout = setTimeout(() => {
this.$refs.watchVideoPlaylist.playNextVideo() this.$refs.watchVideoPlaylist.playNextVideo()
}, 5000) }, 5000)
@ -602,14 +603,14 @@ export default Vue.extend({
message: this.$t('Playing next video in 5 seconds. Click to cancel'), message: this.$t('Playing next video in 5 seconds. Click to cancel'),
time: 5500, time: 5500,
action: () => { action: () => {
clearTimeout(timeout) clearTimeout(this.playNextTimeout)
this.showToast({ this.showToast({
message: this.$t('Canceled next video autoplay') message: this.$t('Canceled next video autoplay')
}) })
} }
}) })
} else if (this.playNextVideo) { } else if (this.playNextVideo) {
const timeout = setTimeout(() => { this.playNextTimeout = setTimeout(() => {
const nextVideoId = this.recommendedVideos[0].videoId const nextVideoId = this.recommendedVideos[0].videoId
this.$router.push( this.$router.push(
{ {
@ -625,7 +626,7 @@ export default Vue.extend({
message: this.$t('Playing next video in 5 seconds. Click to cancel'), message: this.$t('Playing next video in 5 seconds. Click to cancel'),
time: 5500, time: 5500,
action: () => { action: () => {
clearTimeout(timeout) clearTimeout(this.playNextTimeout)
this.showToast({ this.showToast({
message: this.$t('Canceled next video autoplay') message: this.$t('Canceled next video autoplay')
}) })
@ -635,6 +636,8 @@ export default Vue.extend({
}, },
handleRouteChange: function () { handleRouteChange: function () {
clearTimeout(this.playNextTimeout)
if (this.rememberHistory && !this.isLoading && !this.isLive) { if (this.rememberHistory && !this.isLoading && !this.isLive) {
const player = this.$refs.videoPlayer.player const player = this.$refs.videoPlayer.player