vue播放flv格式的直播流

  • 在ios无法播放,安卓可以

安装

复制代码
npm install flv.js --save

页面

js 复制代码
<template>
  <div>
    <video
      ref="videoElement"
      style="width: 100%; height: 100%"
      autoplay
      playsinline
      muted
    ></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>
相关推荐
m0_738120723 小时前
CTFshow系列——命令执行web53-56
前端·安全·web安全·网络安全·ctfshow
Liu.7745 小时前
uniappx鸿蒙适配
前端
叫我阿柒啊6 小时前
Java全栈开发面试实战:从基础到微服务架构
java·vue.js·spring boot·redis·git·full stack·interview
山有木兮木有枝_6 小时前
从代码到创作:探索AI图片生成的神奇世界
前端·coze
ZXT6 小时前
js基础重点复习
javascript
言兴6 小时前
秋招面试---性能优化(良子大胃袋)
前端·javascript·面试
WebInfra8 小时前
Rspack 1.5 发布:十大新特性速览
前端·javascript·github
雾恋8 小时前
我用 trae 写了一个菜谱小程序(灶搭子)
前端·javascript·uni-app
烛阴9 小时前
TypeScript 中的 `&` 运算符:从入门、踩坑到最佳实践
前端·javascript·typescript
Java 码农10 小时前
nodejs koa留言板案例开发
前端·javascript·npm·node.js