安装
npm install flv.js --save
页面
<template><div><videoref="videoElement"style="width: 100%; height: 100%"autoplayplaysinlinemuted></video></div>
</template><script>
import FlvPlayer from "flv.js";export default {data() {return {player: null,streamUrl:"http://180.101.234.45:10554/icvs/stream.flv?puid=201115203876589199&token=18lCFOd-9d&idx=0&stream=0&resType=IV&random=72b8f655-6e51-489a-a38f-af73087be20f",};},mounted() {this.initPlayer();},methods: {async initPlayer() {FlvPlayer.isSupported() && (await FlvPlayer.getFeatureList());this.player = FlvPlayer.createPlayer({type: "flv",url: this.streamUrl,});this.player.attachMediaElement(this.$refs.videoElement);this.player.on(FlvPlayer.Events.MEDIA_INFO, () => {});this.player.load();this.player.play();},},beforeDestroy() {if (this.player) {this.player.destroy();}},
};
</script>