I need to embed a youtube video in a fabricjs canvas. I have tried to do this by inserting an iframe element into a fabricjs image object. This has worked for me to insert a element into the canvas before. However, when inserting an iframe it is not possible.
<input type="text" name="enlace-video" id="enlace-video-yt" value="" placeholder="http://">
<button id="input-video-yt">
Insert YT video
</button>
const ytVideo = document.getElementById('input-video-yt');
ytVideo.addEventListener('click', function (){
var ytvideoURL = document.getElementById("enlace-video-yt").value;
var embedURL = ytvideoURL.replace("watch?v=","embed/");
var divVideo = document.createElement('div');
document.body.appendChild(divVideo);
var iframe = document.createElement('iframe');
iframe.id="new-video";
iframe.src = embedURL;
divVideo.appendChild(iframe);
iframe.addEventListener( "loadedmetadata", function (e) {
var fab_video = new fabric.Image(iframe, {left: 100, top: 50, data: "video"});
canvas.add(fab_video);
}, false );
});
Any other way that makes it possible to insert a youtube video into the canvas would work for me.
To add YouTube Video in canvas, you will need to create a video html tag and assign source to YouTube video link, and then add that video in Canvas as shown in