51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
import download from "downloadjs";
|
|
export function getShowStatus(isLoadingVideo, isEnd, isError) {
|
|
var status = null;
|
|
if (isLoadingVideo) {
|
|
status = 'LOADING';
|
|
}
|
|
if (isError) {
|
|
status = 'ERROR';
|
|
}
|
|
if (isEnd) {
|
|
status = 'END';
|
|
}
|
|
return status;
|
|
}
|
|
|
|
// 下载功能的可配置属性
|
|
|
|
// 视屏截帧、下载
|
|
export var downloadFrame = function downloadFrame(_videoDom, opt) {
|
|
var _ref = opt || {},
|
|
_ref$downloadAble = _ref.downloadAble,
|
|
downloadAble = _ref$downloadAble === void 0 ? true : _ref$downloadAble,
|
|
_ref$fileName = _ref.fileName,
|
|
fileName = _ref$fileName === void 0 ? 'image' : _ref$fileName,
|
|
_ref$fileType = _ref.fileType,
|
|
fileType = _ref$fileType === void 0 ? 'image/png' : _ref$fileType;
|
|
try {
|
|
var video = _videoDom;
|
|
var canvas = document.createElement('canvas');
|
|
var ctx = canvas.getContext('2d');
|
|
var base64;
|
|
|
|
//当视频处于还未加载出来时,截屏为黑色图片
|
|
if (video.readyState === 0) {
|
|
ctx === null || ctx === void 0 || ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
canvas.width = video.offsetWidth;
|
|
canvas.height = video.offsetHeight;
|
|
// @ts-ignore
|
|
ctx.fillStyle = 'black';
|
|
ctx === null || ctx === void 0 || ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
} else {
|
|
canvas.width = video.videoWidth;
|
|
canvas.height = video.videoHeight;
|
|
ctx === null || ctx === void 0 || ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
}
|
|
base64 = canvas.toDataURL(fileType);
|
|
downloadAble && download(base64, fileName);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}; |