받은 소스를 영상으로 보여준다.
비디오의 실행만을 담당하는 비디오 컴포넌트를 만든다.
Video 태그의 기본 형태를 따름
| Parameter | Type | Require |
|---|---|---|
| src | **string | MediaStream** |
| width | number | |
| height | number | |
| autoplay | boolean | |
| controls | boolean | |
| muted | boolean |
import React, { forwardRef, useEffect, useRef } from 'react';
export interface VideoPropType {
src: string | MediaStream;
stream: MediaStream;
width?: number;
height?: number;
autoplay?: boolean;
controls?: boolean;
muted?: boolean;
}
const Video = ({ src, width, height, autoplay, controls, muted }: VideoPropType, ref) => {
const videoRef = ref ? ref : useRef<HTMLVideoElement>(null);
useEffect(() => {
if (!videoRef.current) return;
videoRef.current.autoplay = autoplay;
videoRef.current.controls = controls;
videoRef.current.muted = muted;
if (typeof src === 'string') return;
videoRef.current.srcObject = src;
}, [src]);
return typeof src === 'string' ? (
<video src={src} width={width} height={height} ref={videoRef} />
) : (
<video width={width} height={height} ref={videoRef} />
);
};
export default forwardRef(Video);
| 이름 | 설명 |
|---|---|
| Default | 일반 영상 파일 재생 |
| MediaStream | MediaStram 스트리밍 |