Created
April 3, 2020 10:52
-
-
Save simple17/c0a94a736cac54ffdb1ed6500b8d6a5b to your computer and use it in GitHub Desktop.
[YouTube API Helper] #youtube #helper
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
(() => { | |
var tag = document.createElement('script'); | |
tag.src = "https://www.youtube.com/iframe_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
const createPlayer = (container, videoId, onReady = () => {}, onStateChange = () => {}) => { | |
return new YT.Player(container, { | |
videoId, | |
playerVars: { | |
controls: 0, | |
showinfo: 0,//deprecated :( | |
}, | |
events: { | |
'onReady': onReady, | |
'onStateChange': onStateChange | |
} | |
}); | |
} | |
window.onYouTubeIframeAPIReady = function() { | |
window.ytApiHelper = { | |
createPlayer, | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment