|
@@ -210,25 +210,36 @@ export default defineComponent({
|
|
|
btnLoading.value = false;
|
|
|
};
|
|
|
const getVideoMsg = (file: any) => {
|
|
|
- return new Promise(resolve => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
// let dataURL = '';
|
|
|
const videoElement = document.createElement('video');
|
|
|
videoElement.currentTime = 1;
|
|
|
videoElement.src = URL.createObjectURL(file);
|
|
|
- videoElement.addEventListener('loadeddata', function () {
|
|
|
- const canvas: any = document.createElement('canvas'),
|
|
|
- width = videoElement.videoWidth, //canvas的尺寸和图片一样
|
|
|
- height = videoElement.videoHeight;
|
|
|
- canvas.width = width;
|
|
|
- canvas.height = height;
|
|
|
- canvas.getContext('2d').drawImage(videoElement, 0, 0, width, height); //绘制canvas
|
|
|
- // dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
|
|
|
- // console.log(canvas);
|
|
|
- canvas.toBlob((blob: any) => {
|
|
|
- // console.log(blob);
|
|
|
- resolve(blob);
|
|
|
+ videoElement.addEventListener('loadedmetadata', function () {
|
|
|
+ console.log('loaded in');
|
|
|
+
|
|
|
+ // Listen for 'canplay' to ensure the video is ready for frame capture
|
|
|
+ videoElement.addEventListener('canplay', function () {
|
|
|
+ console.log('Video can play');
|
|
|
+ const canvas: any = document.createElement('canvas'),
|
|
|
+ width = videoElement.videoWidth,
|
|
|
+ height = videoElement.videoHeight;
|
|
|
+
|
|
|
+ canvas.width = width;
|
|
|
+ canvas.height = height;
|
|
|
+ canvas
|
|
|
+ .getContext('2d')
|
|
|
+ .drawImage(videoElement, 0, 0, width, height);
|
|
|
+
|
|
|
+ canvas.toBlob((blob: any) => {
|
|
|
+ resolve(blob);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
+ videoElement.addEventListener('error', function (e) {
|
|
|
+ console.error('Error loading video:', e);
|
|
|
+ reject(e);
|
|
|
+ });
|
|
|
});
|
|
|
};
|
|
|
|