Skip to content

Commit

Permalink
Implement timer for next video to not play automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
kommunarr committed Oct 15, 2024
1 parent 8492051 commit 27f59e0
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ export default defineComponent({
vrProjection: {
type: String,
default: null
},
blockVideoAutoplay: {
type: Boolean,
default: false
}
},
emits: [
'error',
'loaded',
'ended',
'reset-autoplay-interruption-timeout',
'timeupdate',
'toggle-theatre-mode'
],
Expand Down Expand Up @@ -155,6 +160,15 @@ export default defineComponent({
*/
let sortedCaptions

const blockAutoplay = props.blockVideoAutoplay
if (blockAutoplay) {
resetAutoplayInterruptionTimeout()
}

function resetAutoplayInterruptionTimeout() {
emit('reset-autoplay-interruption-timeout')
}

// we don't need to sort if we only have one caption or don't have any
if (props.captions.length > 1) {
// theoretically we would resort when the language changes, but we can't remove captions that we already added to the player
Expand Down Expand Up @@ -1959,6 +1973,8 @@ export default defineComponent({
* @param {KeyboardEvent} event
*/
function keyboardShortcutHandler(event) {
resetAutoplayInterruptionTimeout()

if (!player || !hasLoaded.value) {
return
}
Expand Down Expand Up @@ -2365,6 +2381,9 @@ export default defineComponent({
document.removeEventListener('keydown', keyboardShortcutHandler)
document.addEventListener('keydown', keyboardShortcutHandler)

document.removeEventListener('click', resetAutoplayInterruptionTimeout)
document.addEventListener('click', resetAutoplayInterruptionTimeout)

player.addEventListener('loading', () => {
hasLoaded.value = false
})
Expand Down Expand Up @@ -2673,6 +2692,7 @@ export default defineComponent({
document.body.classList.remove('playerFullWindow')

document.removeEventListener('keydown', keyboardShortcutHandler)
document.removeEventListener('click', resetAutoplayInterruptionTimeout)

if (resizeObserver) {
resizeObserver.disconnect()
Expand Down Expand Up @@ -2768,6 +2788,7 @@ export default defineComponent({
stats,

autoplayVideos,
blockAutoplay,
sponsorBlockShowSkippedToast,

skippedSponsorBlockSegments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
preload="auto"
crossorigin="anonymous"
playsinline
:autoplay="autoplayVideos ? true : null"
:autoplay="autoplayVideos && !blockAutoplay ? true : null"
:poster="thumbnail"
@play="handlePlay"
@pause="handlePause"
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/player-settings/player-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export default defineComponent({
return this.backendPreference !== 'invidious' && !this.backendFallback
},

defaultAutoplayInterruptionInterval: function () {
return parseInt(this.$store.getters.getDefaultAutoplayInterruptionInterval)
},

defaultSkipInterval: function () {
return parseInt(this.$store.getters.getDefaultSkipInterval)
},
Expand Down Expand Up @@ -286,6 +290,7 @@ export default defineComponent({
...mapActions([
'updateAutoplayVideos',
'updateAutoplayPlaylists',
'updateDefaultAutoplayInterruptionInterval',
'updatePlayNextVideo',
'updateEnableSubtitlesByDefault',
'updateProxyVideos',
Expand Down
27 changes: 18 additions & 9 deletions src/renderer/components/player-settings/player-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@
</div>
</div>
<ft-flex-box>
<ft-slider
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
:default-value="defaultSkipInterval"
:min-value="1"
:max-value="70"
:step="1"
value-extension="s"
@change="updateDefaultSkipInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Next Video Interval')"
:default-value="defaultInterval"
Expand All @@ -100,6 +91,24 @@
value-extension="s"
@change="updateDefaultInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Autoplay Interruption Timer')"
:default-value="defaultAutoplayInterruptionInterval"
:min-value="1"
:max-value="12"
:step="1"
value-extension="h"
@change="updateDefaultAutoplayInterruptionInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
:default-value="defaultSkipInterval"
:min-value="1"
:max-value="70"
:step="1"
value-extension="s"
@change="updateDefaultSkipInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Default Volume')"
:default-value="defaultVolume"
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const state = {
baseTheme: 'system',
mainColor: 'Red',
secColor: 'Blue',
defaultAutoplayInterruptionInterval: 3,
defaultCaptionSettings: '{}',
defaultInterval: 5,
defaultPlayback: 1,
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export default defineComponent({
playNextCountDownIntervalId: null,
infoAreaSticky: true,
commentsEnabled: true,
blockVideoAutoplay: false,
autoplayInterruptionTimeout: null,

onMountedRun: false,

Expand Down Expand Up @@ -158,6 +160,9 @@ export default defineComponent({
proxyVideos: function () {
return this.$store.getters.getProxyVideos
},
defaultAutoplayInterruptionInterval: function () {
return this.$store.getters.getDefaultAutoplayInterruptionInterval
},
defaultInterval: function () {
return this.$store.getters.getDefaultInterval
},
Expand Down Expand Up @@ -320,6 +325,7 @@ export default defineComponent({
}

window.addEventListener('beforeunload', this.handleWatchProgress)
this.resetAutoplayInterruptionTimeout()
},

changeTimestamp: function (timestamp) {
Expand Down Expand Up @@ -1619,6 +1625,12 @@ export default defineComponent({
this.updatePlaylistLastPlayedAt({ _id: playlist._id })
},

resetAutoplayInterruptionTimeout() {
clearTimeout(this.autoplayInterruptionTimeout)
this.autoplayInterruptionTimeout = setTimeout(() => { this.blockVideoAutoplay = true }, this.defaultAutoplayInterruptionInterval * 3_600_000)
this.blockVideoAutoplay = false
},

...mapActions([
'updateHistory',
'updateWatchProgress',
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
:theatre-possible="theatrePossible"
:use-theatre-mode="useTheatreMode"
:vr-projection="vrProjection"
:block-video-autoplay="blockVideoAutoplay"
class="videoPlayer"
@error="handlePlayerError"
@loaded="handleVideoLoaded"
@timeupdate="updateCurrentChapter"
@ended="handleVideoEnded"
@reset-autoplay-interruption-timeout="resetAutoplayInterruptionTimeout"
@toggle-theatre-mode="useTheatreMode = !useTheatreMode"
/>
<div
Expand Down
3 changes: 2 additions & 1 deletion static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ Settings:
Skip by Scrolling Over Video Player: Skip by Scrolling Over Video Player
Display Play Button In Video Player: Display Play Button In Video Player
Enter Fullscreen on Display Rotate: Enter Fullscreen on Display Rotate
Next Video Interval: Next Video Interval
Next Video Interval: Autoplay Countdown Timer
Autoplay Interruption Timer: Autoplay Interruption Timer
Fast-Forward / Rewind Interval: Fast-Forward / Rewind Interval
Default Volume: Default Volume
Default Playback Rate: Default Playback Rate
Expand Down

0 comments on commit 27f59e0

Please sign in to comment.