基于如何将视频渲染到画布的Konva
文档,我想通过直接从Konva.Image
实例访问视频参考来播放视频。下面是一个人为的示例,用于模拟我从组件外部动态播放视频的目标。即使imageRef.current.image()
返回视频元素引用,以下内容也不会按预期播放视频。关于如何访问视频参考的任何建议?
import React, { useEffect, useContext, useState } from 'react'
import { Image } from "react-konva";
import Konva from 'konva'
export const MainVideo = ({ shape, dispatch }) => {
const imageRef = React.useRef(null);
const video = document.createElement('video');
video.setAttribute('src',shape.url);
useEffect(() => {
if(imageRef) {
imageRef.current.image().play();
const layer = imageRef.current.getLayer();
const anim = new Konva.Animation(() => {
}, layer);
anim.start()
}
}, [imageRef])
return (
<Image
ref={imageRef}
opacity={shape.o}
id={shape.id}
image={video}
x={shape.x}
y={shape.y}
zIndex={0}
height={360}
width={640} />
)
}