Last active
August 27, 2022 15:48
-
-
Save el3um4s/549a83219a54dd2e93e9be25c6eb8104 to your computer and use it in GitHub Desktop.
MEDIUM - How To Create a Simple YouTube Player With JavaScript - 02
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
export async function CreatePlayer(iframeId, eventHandlers) { | |
return new Promise((resolve) => { | |
if (!eventHandlers) eventHandlers = {}; | |
eventHandlers["onReady"] = (e) => resolve(e.target); | |
eventHandlers["onPlayerStateChange"] = (e) => resolve(e.target); | |
new globalThis["YT"]["Player"](iframeId, { | |
events: eventHandlers, | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment