Trigger autoplay when allowed

This commit is contained in:
Sam Carlton 2021-04-27 17:21:03 -05:00
parent bc7a5de462
commit f7af4fb950

View file

@ -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
}
},