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

View File

@ -867,71 +867,57 @@ export default Vue.extend({
}, },
handleVideoEnded: function () { handleVideoEnded: function () {
if (!this.watchingPlaylist && !this.playNextVideo) {
return
}
const nextVideoInterval = this.defaultInterval const nextVideoInterval = this.defaultInterval
if (this.watchingPlaylist) { this.playNextTimeout = setTimeout(() => {
this.playNextTimeout = setTimeout(() => { const player = this.$refs.videoPlayer.player
const player = this.$refs.videoPlayer.player if (player !== null && player.paused()) {
if (player !== null && player.paused()) { if (this.watchingPlaylist) {
this.$refs.watchVideoPlaylist.playNextVideo() this.$refs.watchVideoPlaylist.playNextVideo()
} } else {
}, 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()) {
const nextVideoId = this.recommendedVideos[0].videoId const nextVideoId = this.recommendedVideos[0].videoId
this.$router.push( this.$router.push({
{ path: `/watch/${nextVideoId}`
path: `/watch/${nextVideoId}` })
}
)
this.showToast({ this.showToast({
message: this.$t('Playing Next Video') 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({ this.showToast({
message: this.$t('Playing next video in 5 seconds. Click to cancel'), message: this.$tc('Playing Next Video Interval', countDownTimeLeftInSecond, { nextVideoInterval: countDownTimeLeftInSecond }),
time: 5500, // To avoid message flashing
// `time` is manually tested to be 700
time: 700,
action: () => { action: () => {
clearTimeout(this.playNextTimeout) clearTimeout(this.playNextTimeout)
clearInterval(countDownIntervalId)
this.showToast({ this.showToast({
message: this.$t('Canceled next video autoplay') 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 () { handleRouteChange: function () {

View File

@ -171,7 +171,7 @@ Settings:
Proxy Videos Through Invidious: Proxy Videos Through Invidious Proxy Videos Through Invidious: Proxy Videos Through Invidious
Autoplay Playlists: Autoplay Playlists Autoplay Playlists: Autoplay Playlists
Enable Theatre Mode by Default: Enable Theatre Mode by Default 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 Volume: Default Volume
Default Playback Rate: Default Playback Rate Default Playback Rate: Default Playback Rate
Default Video Format: Default Video Format: