0
点赞
收藏
分享

微信扫一扫

vue 预览视频

扒皮狼 2023-09-14 阅读 46

1.预览本地文件

          1.1 直接给video或者embed的src赋值本地路径

<video :src="videoUrl"></video>
// 或者 使用embed标签
 <embed :src="videoUrl" />

            1.2 读取文件流形式

<input type="file" ref="file" />
<video :src="videoUrl"></video>

const blob = new Blob([this.$refs.file.files[0]], {type: 'video/mp4'})
 const reader = new FileReader();
 reader.onload = (ev) => {
     const src = ev.target.result
     that.videoUrl=src
    }
 reader.readAsDataURL(blob); 

2. 从服务器接口或者视频的数据流

<video :src="videoUrl"></video>

api(param).then(res => {
     const blob = new Blob(res.data, {type: 'video/mp4'})
     const reader = new FileReader();
     reader.onload = (ev) => {
         const src = ev.target.result
         that.videoUrl=src
      }
      reader.readAsDataURL(blob); 
})
举报

相关推荐

0 条评论