vue3 flvjs播放flv直流视频
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue

·
<template>
<div class="videoBox">
<video id="videoElement" autoplay muted style="width: 100%; height: 100%; object-fit: fill"></video>
</div>
</template>
<script setup >
import { ref, reactive, nextTick, onMounted, onUnmounted } from "vue"
import flvjs from 'flv.js';
const flvPlayer = ref(null);
const createVideo = () => {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
flvPlayer.value = flvjs.createPlayer(
{
type: 'flv',
url: '', //你的url地址
isLive: true,
hasAudio: false,
},
{
enableWorker: false,
fixAudioTimestampGap: false
}
);
flvPlayer.value.attachMediaElement(videoElement);
flvPlayer.value.load();
setTimeout(function () {
flvPlayer.value.play();
}, 300);
//处理视频播放错误的语法
// flvPlayer.value.on('error', () => {
// // message.error(`视频加载失败,请稍候重试!`);
// return false;
// });
}
};
const destroy = () => {
flvPlayer.value.pause(); //暂停播放数据流
flvPlayer.value.unload(); //取消数据流加载
flvPlayer.value.detachMediaElement(); //将播放实例从节点中取出
flvPlayer.value.destroy(); //销毁播放实例
flvPlayer.value = null;
};
defineExpose({ destroy });
onMounted(() => {
createVideo();
});
onUnmounted(async () => {
destroy()
});
</script>
<style scoped>
.videoBox {
width: 800px;
height: 450px;
border: solid 1px #ccc;
}
</style>




vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:19 天前 )
9e887079
[skip ci] 11 个月前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
更多推荐
所有评论(0)