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.
This commit is contained in:
Svallinn 2021-04-29 19:33:13 +01:00
parent 76260d9c4c
commit e696af3f7a
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
3 changed files with 36 additions and 50 deletions

View File

@ -62,7 +62,7 @@
</div>
<ft-flex-box>
<ft-slider
:label="$t('Settings.Player Settings.Playlist Next Video Interval')"
:label="$t('Settings.Player Settings.Next Video Interval')"
:default-value="defaultInterval"
:min-value="0"
:max-value="60"

View File

@ -867,71 +867,57 @@ export default Vue.extend({
},
handleVideoEnded: function () {
if (!this.watchingPlaylist && !this.playNextVideo) {
return
}
const nextVideoInterval = this.defaultInterval
if (this.watchingPlaylist) {
this.playNextTimeout = setTimeout(() => {
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 () {

View File

@ -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: