Skip to content

Commit

Permalink
Update implementation to block next video autoplay
Browse files Browse the repository at this point in the history
i.e., instead of 'start video automatically' autoplay
  • Loading branch information
kommunarr committed Oct 16, 2024
1 parent 27f59e0 commit 128f12a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,11 @@ export default defineComponent({
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 @@ -160,15 +155,6 @@ 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 @@ -1973,8 +1959,6 @@ export default defineComponent({
* @param {KeyboardEvent} event
*/
function keyboardShortcutHandler(event) {
resetAutoplayInterruptionTimeout()

if (!player || !hasLoaded.value) {
return
}
Expand Down Expand Up @@ -2381,9 +2365,6 @@ 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 @@ -2692,7 +2673,6 @@ export default defineComponent({
document.body.classList.remove('playerFullWindow')

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

if (resizeObserver) {
resizeObserver.disconnect()
Expand Down Expand Up @@ -2788,7 +2768,6 @@ 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 && !blockAutoplay ? true : null"
:autoplay="autoplayVideos ? true : null"
:poster="thumbnail"
@play="handlePlay"
@pause="handlePause"
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default defineComponent({
beforeRouteLeave: async function (to, from, next) {
this.handleRouteChange()
window.removeEventListener('beforeunload', this.handleWatchProgress)
document.removeEventListener('click', this.resetAutoplayInterruptionTimeout)

if (this.$refs.player) {
await this.$refs.player.destroyPlayer()
Expand Down Expand Up @@ -324,6 +325,9 @@ export default defineComponent({
this.getVideoInformationLocal()
}

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

window.addEventListener('beforeunload', this.handleWatchProgress)
this.resetAutoplayInterruptionTimeout()
},
Expand Down Expand Up @@ -1192,6 +1196,12 @@ export default defineComponent({
return
}

if (this.blockVideoAutoplay) {
showToast(this.$t('Canceled next video autoplay due to inactivity'))
this.resetAutoplayInterruptionTimeout()
return
}

if (this.watchingPlaylist && this.getPlaylistPauseOnCurrent()) {
this.disablePlaylistPauseOnCurrent()
return
Expand Down Expand Up @@ -1627,7 +1637,7 @@ export default defineComponent({

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

Expand Down
2 changes: 0 additions & 2 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
: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
1 change: 1 addition & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ Playlist will not pause when current video is finished: Playlist will not pause
Playlist will pause when current video is finished: Playlist will pause when current video is finished
Playing Next Video Interval: Playing next video in no time. Click to cancel. | Playing next video in {nextVideoInterval} second. Click to cancel. | Playing next video in {nextVideoInterval} seconds. Click to cancel.
Canceled next video autoplay: Canceled next video autoplay
Canceled next video autoplay due to inactivity: Canceled next video autoplay due to inactivity

Default Invidious instance has been set to {instance}: Default Invidious instance has been set to {instance}
Default Invidious instance has been cleared: Default Invidious instance has been cleared
Expand Down

0 comments on commit 128f12a

Please sign in to comment.