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>
相关推荐
神奇的程序员8 小时前
我的软件冲进苹果商店下载榜前 50 了
前端
阳光是sunny8 小时前
别再被 worktree 绕晕了!AI 编程时代你必须掌握的 Git 隔离神器
前端·人工智能·后端
万少9 小时前
万少的博客 - 技术分享与解决方案
前端·javascript·后端
尘世中一位迷途小书童12 小时前
用 Cesium 撸了一个森林火情监控大屏,弧线、粒子、发光效果都齐了
前端·javascript
IT_陈寒12 小时前
垃圾回收器选错了,我的Java服务内存炸了
前端·人工智能·后端
月光下的丝瓜13 小时前
Flutter 国内安装指南
前端·flutter
先吃饱再说13 小时前
JavaScript中`this` 的“千层套路”:从默认绑定到箭头函数的五种指向
javascript
玄星啊13 小时前
AI 编程的第 30 天,我怀念古法 Coding 了
前端·ai编程
Jolyne_13 小时前
Angular基础速通
前端·angular.js
foxire14 小时前
基于nodejs实现服务端内核引擎
javascript