videoSuccess(res,file,fileList){
this.findvideocover(file.url,file);
},
findvideocover(url,file) {
const video = document.createElement("video")
video.src=url
var canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d');
video.crossOrigin = 'anonymous'
video.currentTime = 1
video.oncanplay = () => {
console.log(video.clientWidth, video.clientHeight);
canvas.width = video.clientWidth ? video.clientWidth : 320;
canvas.height = video.clientHeight ? video.clientHeight : 320;
ctx.drawImage(video, 0, 0, canvas.width,canvas.height)
this.videoFirstimgsrc = canvas.toDataURL ("image/png");
file.url = this.videoFirstimgsrc;
const fileBolb = this.base64toFile(this.videoFirstimgsrc, this.getFileName(file))
this.getFirstPngUrl(fileBolb);
video.remove();
canvas.remove();
}
},
base64toFile (baseUrl, filename = 'file') {
let arr = baseUrl.split(',');
let type = arr[0].match(/:(.*?);/)[1];
let bytes = atob(arr[1]);
let n = bytes.length
let bufferArray = new Uint8Array(n);
while (n--) {
bufferArray[n] = bytes.charCodeAt(n);
}
return new File([bufferArray ],filename,{ type });
},
getFirstPngUrl(file){
const fd = new FormData();
fd.append('file',file);
fd.append('sid',this.uploadData.sid);
this.$post('http://www.baidu.com', fd, { headers: {'Content-Type': 'multipart/form-data', },}).then(res=>{
this.videoFirstimgsrc = res.url;
this.videoWriteFileList[0].url = res.url;
})
},
getFileName(file){
const type = file.raw.type.split("/")[1];
let name = '';
if(type){
name = file.raw.name.substring(0, file.raw.name.indexOf(`.${type}`));
}
return `${name}.png`;
},