当前位置: 首页 > news >正文

vue2使用flv.js在浏览器打开flv格式视频

组件地址:GitHub - bilibili/flv.js: HTML5 FLV Player

flv.js 仅支持 H.264 和 AAC/MP3 编码的 FLV 文件。如果视频文件使用了其他编码格式就打不开。

 flv.vue

<template><div><el-dialog :visible.sync="innerVisibleFlv" :close-on-press-escape="false" :close-on-click-modal="false"append-to-body width="800px" top="15vh" title="" class="modify" :before-close="handleClose"><video ref="videoPlayer" class="video-js vjs-default-skin" controls preload="auto" width="100%" height="99%"><!-- 这里不需要添加 source 标签,因为 flv.js 会动态处理 --></video></el-dialog></div>
</template><script>
import flvjs from 'flv.js';export default {name: 'FlvPlayer',props: {innerVisibleFlv: {type: Boolean,default: true},flvPath: {type: String}},data() {return {flvPlayer: null,videoUrl: null,};},watch: {flvPath: {deep: true,immediate: true,handler (n, o) {if (n) {this.videoUrl = n;}}}},mounted() {this.$nextTick(() => {this.initFlvPlayer();})},beforeDestroy() {if (this.flvPlayer) {this.flvPlayer.destroy();}},methods: {initFlvPlayer() {if (flvjs.isSupported()) {const videoElement = this.$refs.videoPlayer;this.flvPlayer = flvjs.createPlayer({type: 'flv',// url: this.videoUrl,  # http://localhost:8080/aaa/flv/25012001.flvurl: '/flv/aaa/flv/25012001.flv', # 本地测试这么写,跨域问题,修改proxyConfig.js});this.flvPlayer.attachMediaElement(videoElement);this.flvPlayer.load();this.flvPlayer.play();} else {console.error('Your browser does not support FLV playback.');}},handleClose () {this.$emit('handleClose');},}
};
</script><style scoped></style>

碰到问题

1、本地开发跨域

修改proxyConfig.js文件,添加下面的内容;修改组件中的url地址为 /flv/xxx

module.exports = {....proxyTable: {'/flv': {target: 'http://localhost:8080', changeOrigin: true, pathRewrite: { '^/flv': ''  }}}
}

ps:碰到过这个问题,还部署到tomcat中测试了,也是无法正常播放,现在想想当时是因为文件的编码不对造成的。

2、文件还是无法播放,原因是flv文件的编码不对

转换工具:在线 & 免费地将 MP4 转换成 FLV — Convertio

 到此,在浏览器可以正常打开。

http://www.lryc.cn/news/523924.html

相关文章:

  • OpenCV相机标定与3D重建(61)处理未校准的立体图像对函数stereoRectifyUncalibrated()的使用
  • [cg] glProgramBinary
  • LeetCode hot 力扣热题100 二叉树的最大深度
  • 速通Docker === 网络
  • 【MySQL — 数据库基础】深入解析MySQL常用数据类型
  • Linux高级--3.3.1 C++ spdlog 开源异步日志方案
  • 电梯系统的UML文档05
  • 如何使 LLaMA-Factory 支持 google/gemma-2-2b-jpn-it 的微调
  • MySQL中日期和时间戳的转换:字符到DATE和TIMESTAMP的相互转换
  • HarmonyOS NEXT开发进阶(十):UIAbility 组件交互
  • 深入探索Math.NET:开启高效数值计算之旅
  • AI编程工具横向评测--Cloudstudio塑造完全态的jupyter notebook助力数据分析应用开发
  • 【2024 CSDN博客之星】技术洞察类:从DeepSeek-V3的成功,看MoE混合专家网络对深度学习算法领域的影响(MoE代码级实战)
  • Linux——入门基本指令汇总
  • 54,【4】BUUCTF WEB GYCTF2020Ezsqli
  • 【Leetcode 热题 100】45. 跳跃游戏 II
  • C/C++ 时间复杂度(On)
  • 【STM32-学习笔记-10-】BKP备份寄存器+时间戳
  • React 中hooks之 React.memo 和 useMemo用法总结
  • 日志收集Day001
  • 机器人“大脑+小脑”范式:算力魔方赋能智能自主导航
  • python程序跑起来后,然后引用的数据文件发生了更新,python读取的数据会发生变化吗
  • VSCode最新离线插件拓展下载方式
  • 算法题目总结-栈和队列
  • IO进程----进程
  • 【机器学习实战高阶】基于深度学习的图像分割
  • 「免填邀请码」赋能各类APP,提升转化率与用户体验
  • 基于海思soc的智能产品开发(视频的后续开发)
  • 创建 pdf 合同模板
  • 2024 年度学习总结