From f7af4fb950629d5c1b7c5daa126dfdbb6aa39c3e Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Tue, 27 Apr 2021 17:21:03 -0500 Subject: [PATCH] Trigger autoplay when allowed --- components/video/player.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/video/player.vue b/components/video/player.vue index 9c61bed..624481b 100644 --- a/components/video/player.vue +++ b/components/video/player.vue @@ -220,7 +220,13 @@ export default { // this.frameId = `youtube-bg-${this._uid}` this.detectAutoplay() - .then( statuses => console.log(statuses) ) + .then( ({ willAutoplay }) => { + // If we're allowed to autoplay + // then start loading the player + if ( willAutoplay === true ) { + this.startPlayerLoad() + } + }) }, methods: { scrollRow ( timestamp ) { @@ -240,16 +246,15 @@ export default { async detectAutoplay () { - if ( !process.client ) return false + if ( !process.client ) return { willAutoplay: false } const { default: canAutoPlay } = await import('can-autoplay') const willAutoplay = await canAutoPlay.video() - const willAutoplayMuted = await canAutoPlay.video({ muted: true, inline: true }) + // const willAutoplayMuted = await canAutoPlay.video({ muted: true, inline: true }) return { - willAutoplay, - willAutoplayMuted + willAutoplay: willAutoplay.result } },