51 lines
939 B
TypeScript
51 lines
939 B
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import Empty from './Empty';
|
|
import VideoCanvas from './VideoCanvas';
|
|
|
|
interface VideoPlayerProps {
|
|
deviceId: string;
|
|
idx: number;
|
|
title?: string;
|
|
className?: string;
|
|
noCrop?: boolean;
|
|
|
|
video?: HTMLVideoElement;
|
|
error?: boolean;
|
|
ready?: boolean;
|
|
}
|
|
const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|
deviceId,
|
|
idx,
|
|
title,
|
|
className = '',
|
|
noCrop,
|
|
video, error, ready
|
|
}) => {
|
|
|
|
|
|
const viewTitles = ['前视图', '后视图', '左视图', '右视图'];
|
|
const currentTitle = title || viewTitles[idx - 1];
|
|
|
|
if (!deviceId || error) {
|
|
return <Empty description="视频源连接失败" />;
|
|
}
|
|
|
|
if (!ready || !video) {
|
|
return <Empty description="视频加载中..." />;
|
|
}
|
|
|
|
return (
|
|
<VideoCanvas
|
|
key={`canvas-${deviceId}-${idx}`}
|
|
video={video}
|
|
idx={idx}
|
|
title={currentTitle}
|
|
className={className}
|
|
noCrop={noCrop}
|
|
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default VideoPlayer;
|