From fc43a0a3ab3611465cfba9dbfa53db637e7f06fd Mon Sep 17 00:00:00 2001 From: Craig Date: Wed, 12 Feb 2020 04:16:49 +0000 Subject: [PATCH] mute video if not focused --- client/src/components/video.vue | 4 ++++ client/src/store/video.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/client/src/components/video.vue b/client/src/components/video.vue index 65a847a..f50aa90 100644 --- a/client/src/components/video.vue +++ b/client/src/components/video.vue @@ -312,6 +312,10 @@ this._video.addEventListener('canplaythrough', () => { this.$accessor.video.setPlayable(true) if (this.autoplay) { + if (!document.hasFocus()) { + this.$accessor.video.setMuted(true) + } + this.$nextTick(() => { this.$accessor.video.play() }) diff --git a/client/src/store/video.ts b/client/src/store/video.ts index 45d7add..21c2883 100644 --- a/client/src/store/video.ts +++ b/client/src/store/video.ts @@ -47,6 +47,11 @@ export const mutations = mutationTree(state, { } }, + setMuted(state, muted: boolean) { + state.muted = muted + set('mute', muted) + }, + toggleMute(state) { state.muted = !state.muted set('mute', state.muted)