Youtube Html5 Video Player Codepen
// Load the IFrame Player API code asynchronously var tag = document.createElement('script'); tag.src = "https://youtube.com"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); let player; function onYouTubeIframeAPIReady() player = new YT.Player('player', videoId: 'dQw4w9WgXcQ', // Replace with your video ID playerVars: 'controls': 0, // Hide default YouTube controls 'modestbranding': 1, 'rel': 0 , events: 'onReady': onPlayerReady ); function onPlayerReady(event) // Bind buttons document.getElementById('playBtn').addEventListener('click', () => player.playVideo()); document.getElementById('pauseBtn').addEventListener('click', () => player.pauseVideo()); Use code with caution. Pro Tip for CodePen Users
We calculate the click position relative to the width of the progress bar. youtube html5 video player codepen
When working on , ensure your JavaScript settings are set to Babel if you plan to use ES6 features, and remember that the onYouTubeIframeAPIReady function must be in the global scope for the YouTube script to find it. Best Practices for Performance // Load the IFrame Player API code asynchronously