Completed buildPlayer method for youtubeEmbedHandler

This commit is contained in:
rainbow napkin 2025-05-08 08:22:42 -04:00
parent 1344756449
commit 1b0caa5e02
6 changed files with 43 additions and 19 deletions

View file

@ -312,23 +312,39 @@ class youtubeEmbedHandler extends mediaHandler{
}
buildPlayer(){
//If the embed API has loaded
if(this.client.ytEmbedAPILoaded){
//Create a new youtube player using the official YT iframe-embed api
this.video = new YT.Player('video', {
//Inject video id
videoID: media.id,
//Set up event listeners (NGL kinda nice of google to do it this way...)
events: {
'onReady': this.embedPlayer.bind(this)
}
});
//If the embed API hasn't loaded
if(!this.client.ytEmbedAPILoaded){
//Complain and stop
return console.warn("youtubeEmbedHandler.buildPlayer() Called before YT Iframe API Loaded, waiting on refresh to rebuild...");
}
//Clear out the player title so that youtube's baked in title can do it's thing.
//This will be replaced once we complete the full player control and remove the defualt youtube UI
this.player.title.textContent = "";
//Create temp div for yt api to replace
const tempDiv = document.createElement('div');
//Name the div
tempDiv.id = "youtube-embed-player"
//Append it to the video container
this.player.videoContainer.appendChild(tempDiv);
//Create a new youtube player using the official YT iframe-embed api
this.video = new YT.Player('youtube-embed-player', {
//Inject video id
videoId: this.nowPlaying.id,
//Set up event listeners (NGL kinda nice of google to do it this way...)
events: {
'onReady': this.initializePlayer.bind(this)
}
});
//Call derived function
super.buildPlayer();
}
embedPlayer(){
initializePlayer(){
//Kick the video off
this.video.playVideo();
}
}