vue 预览视频

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); 
  1. 从服务器接口或者视频的数据流

    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);
    })

相关推荐
ly76896 小时前
CSS 从入门到进阶:系统掌握现代网页样式与布局
前端·css
SWAGGY..6 小时前
【C++初阶】:(15)模板进阶--从非类型参数到模板特化与分离编译
java·服务器·前端
YHHLAI6 小时前
从「跑分」到「干活」:Benchmark 与 GPT 5.6 的两种叙事
大数据·前端·人工智能·react.js·前端框架
BigTopOne7 小时前
ArLiveLite 用到的 C++/JNI 技术点
前端
BigTopOne7 小时前
ArLiveLite 技术架构-Lite
前端
BigTopOne7 小时前
ArLiveLite-具体功能
前端
BigTopOne7 小时前
ArLiveLite -具体功能
前端
Sherotree7 小时前
理解 JWT:三段分别是什么
前端·ai·开源
BigTopOne7 小时前
ArLiveLite 用到的 FFmpeg API
前端
小弥儿7 小时前
GPT Image 2 提示词库,把散落的生图提示词变成工程资产
开发语言·javascript·gpt·学习