Last active
March 1, 2023 13:55
-
-
Save NickDeckerDevs/5213df3ff7e79161bbd15c175e6c6726 to your computer and use it in GitHub Desktop.
hubspot video status handling? via Stuart Grant - Dev @ King Post Studio, LLC (hubspot dev slack)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SET_PLAYER_STATUS = 'SET_PLAYER_STATUS'; | |
const hsVideos = window.hsVideoApi?.getPlayers(); | |
const videoEls = document.querySelectorAll('.video-container'); | |
function manageVideoStatus() { | |
videoEls.forEach((videoEl) => { | |
const iframe = videoEl.querySelector('iframe'); | |
if (iframe) { | |
const videoId = iframe.getAttribute('id')?.replace('hs_player_', ''); | |
const hsVideo = hsVideos.find(({ id }) => id === videoId); | |
if (hsVideo) { | |
if (isElInView(iframe)) { | |
if (hsVideo.status !== statuses.playing) { | |
hsVideo.postMessageToPlayer(SET_PLAYER_STATUS, { status: statuses.playing }); | |
} | |
} else if (hsVideo.status !== statuses.paused) { | |
hsVideo.postMessageToPlayer(SET_PLAYER_STATUS, { status: statuses.paused }); | |
} | |
} | |
} | |
}); | |
} | |
window.addEventListener('scroll', manageVideoStatus); | |
manageVideoStatus(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you, it works just fine