leafer-ui icon indicating copy to clipboard operation
leafer-ui copied to clipboard

如何使用leaferjs播放视频?

Open overdev-l opened this issue 2 years ago • 4 comments

overdev-l avatar Aug 03 '23 14:08 overdev-l

我们后面计划会增加视频组件。

目前可以通过自定义组件 或Canvas 组件同步视频帧: http://localhost:5173/ui/guide/display/Canvas.html https://leaferjs.com/ui/guide/display/Custom.html

再通过AnimateEvent.FRAME事件,forceUpdate('fill') 每一帧的画面: https://leaferjs.com/ui/guide/animate/ https://leaferjs.com/ui/guide/property/layer.html#forceupdate

leaferjs avatar Aug 03 '23 14:08 leaferjs

如果使用canvas同步视频帧,声音源的播放世纪还是video标签吧

overdev-l avatar Aug 03 '23 14:08 overdev-l

对的,可以参考目前网络上canvas播放视频的方法

leaferjs avatar Aug 03 '23 22:08 leaferjs

最近刚做了类似需求,简单贴下代码抛砖引玉

const renderVideo = (src: string) => { const canvas = new Canvas({ width: 750, height: 1334 }); const { context } = canvas;

const video = document.createElement("video"); video.crossOrigin = "anonymous"; video.src = src; video.autoplay = true; video.muted = true; video.loop = true;

if (video.paused) { video.play(); } leafer.add(canvas);

(function draw() { context!.drawImage(video, 0, 0, 750, 1334); canvas.paint(); requestAnimationFrame(draw); })(); };

JazzOne avatar Jul 11 '24 01:07 JazzOne