Commit abb98961 authored by verestrasz's avatar verestrasz

update

parent 417e8adc
...@@ -81,47 +81,34 @@ Vue.mixin({ ...@@ -81,47 +81,34 @@ Vue.mixin({
}) })
}, },
getVideoBase64(url,width=400,height=240) { getVideoBase64(url,width=400,height=240) {
// url="http://localhost:8080/f5f7c8e13cd6f11ef8eed12ea93a642c.MP4"
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
// let dataURL = '';
// let video = document.createElement("video");
// video.setAttribute('crossOrigin', 'anonymous');//处理跨域
// video.setAttribute('src', url);
// video.setAttribute('width', width);
// video.setAttribute('height', height);
// video.addEventListener('loadeddata', function () {
// let canvas = document.createElement("canvas"),
// width = video.width, //canvas的尺寸和图片一样
// height = video.height;
// canvas.width = width;
// canvas.height = height;
// canvas.getContext("2d").drawImage(video, 0, 0, width, height); //绘制canvas
// dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
// resolve(dataURL);
// });
let dataURL="" let dataURL=""
// 在缓存中创建video标签 // 在缓存中创建video标签
var video = document.createElement("video") var video = document.createElement("video")
video.setAttribute('crossOrigin', 'anonymous');//处理跨域 // video.setAttribute('crossOrigin', 'anonymous');//处理跨域
// video.setAttribute('useCORS', true);//处理跨域
video.setAttribute('src', url); video.setAttribute('src', url);
// 再添加一个静音的属性,否则自动播放会有声音 // 再添加一个静音的属性,否则自动播放会有声音
video.setAttribute('muted', 'muted') // video.setAttribute('muted', 'muted')
// 通过setAttribute给video dom元素添加自动播放的属性,因为视频播放才 // 通过setAttribute给video dom元素添加自动播放的属性,因为视频播放才
video.setAttribute('autoplay', 'autoplay') // video.setAttribute('autoplay', 'autoplay')
video.setAttribute('width', width); video.setAttribute('width', width);
video.setAttribute('height', height); video.setAttribute('height', height);
video.setAttribute('controls','controls')
// video注册canplay自动播放事件 // document.body.appendChild(video)
video.addEventListener('canplay', function() { // // video注册canplay自动播放事件
video.addEventListener('loadeddata', function() {
let canvas = document.createElement("canvas"), let canvas = document.createElement("canvas"),
width = video.width, //canvas的尺寸和图片一样 width = video.width, //canvas的尺寸和图片一样
height = video.height; height = video.height;
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
canvas.getContext("2d").drawImage(video, 0, 0, width, height); //绘制canvas canvas.getContext("2d").drawImage(video, 0, 0, width, height); //绘制canvas
console.log(canvas)
dataURL = canvas.toDataURL('image/jpeg'); //转换为base64 dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
// video.remove() video.remove()
canvas.remove()
console.log(dataURL)
resolve(dataURL); resolve(dataURL);
}); });
}) })
......
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
.video-play-icon { .video-play-icon {
position: absolute; position: absolute;
top: 50%; top: calc(~"50% - 38px");
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment