是否可以在Fabricjs帆布中嵌入iFrame元素以将YouTube视频插入其中?
我需要将YouTube视频嵌入到Fabricjs画布中。我试图通过将iframe元素插入Fabricjs Image对象来做到这一点。这对我来说是为了将元素插入画布之前。但是,在插入iframe时,这是不可能的。
<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 );
});
任何其他方法都可以将YouTube视频插入画布中的任何其他方式都对我有用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在画布中添加YouTube视频,
您将需要创建视频HTML标签并将源分配给YouTube视频链接,然后在画布中添加该视频,如图所示
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