Created
October 30, 2020 21:29
-
-
Save chrisbradshaw/aa2739f1200f843b8d067e3d13935728 to your computer and use it in GitHub Desktop.
youtube-pfp.html
This file contains 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
<!DOCTYPE html> | |
<html> | |
<style> | |
body { | |
text-align: center; | |
} | |
#player { | |
margin: 40px auto; | |
} | |
</style> | |
<body> | |
<!-- 1. The <iframe> (and video player) will replace this <div> tag. --> | |
<div id="player"></div> | |
<script> | |
var tag = document.createElement('script'); | |
tag.src = 'https://www.youtube.com/iframe_api'; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
var player; | |
var done = false; | |
function onYouTubeIframeAPIReady() { | |
player = new YT.Player('player', { | |
height: '720', | |
width: '1080', | |
videoId: 'NVDTISBdHKg', | |
events: { | |
onReady: event => { | |
event.target.playVideo(); | |
console.log('YouTubePFP.onReady'); | |
}, | |
onStateChange: event => { | |
if (event.data == YT.PlayerState.PLAYING && !done) { | |
setTimeout(stopVideo, 6000); | |
done = true; | |
} | |
}, | |
onAdStart: () => { | |
console.log('YouTubePFP.onAdStart'); | |
}, | |
onAdSkip: () => { | |
console.log('YouTubePFP.onAdSkip'); | |
}, | |
onAdEnd: () => { | |
console.log('YouTubePFP.onAdEnd'); | |
} | |
}, | |
embedConfig: { | |
primaryThemeColor: '#FFFF00', | |
adsConfig: { | |
adTagParameters: { | |
iu: "5485/US/popsugar/fitness/video/youtube", | |
cust_params: "nid=47219495" | |
}, | |
nonPersonalizedAd: true | |
} | |
} | |
}); | |
} | |
function stopVideo() { | |
player.stopVideo(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment