使用 阿里云 播放器播放 .flv 和 hls(.m3u8) 格式的视频流

一、使用 阿里云 播放器播放 .flv 和 hls(.m3u8) 格式的视频流

官方教程:https://help.aliyun.com/document_detail/125570.htm?spm=a2c4g.11186623.0.0.4a3b125de04RLI#task-1997027

在 vue 项目中的 index.html 文件中,引入视频资源

<link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.11.0/skins/default/aliplayer-min.css" />
<script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.11.0/aliplayer-h5-min.js"></script>

封装组件 base_video_Flv

<template>
  <!-- 可播放 hls(.m3u8)、.flv格式的视频直播流 -->
  <div :id="videoId" :style="{ width: videoWidth, height: videoHeight }"></div>
</template>

<script>
export default {
  props: {
    //视频地址、video的id值
    vData: {
      type: Object,
      default: () => {
        return {
          hlsurl: "", //视频url地址
          cameraId: "", //id
          player: null,
        };
      },
    },
    //视频宽度
    videoWidth: {
      type: String,
      default: "100%",
    },
    //视频高度
    videoHeight: {
      type: String,
      default: "100%",
    },
  },
  data() {
    return {
      videoId: "",
    };
  },
  methods: {
    getVideo(url, videoId) {
      this.player = new Aliplayer(
        {
          id: videoId,
          //source:"http://10.182.28.116:8080/live/00000011-0000-0000-0000-0a3b010b401f.flv", //播放地址,可以是第三方直播地址,或阿里云直播服务中的拉流地址。
          //source:"https://live-hls-web-aje.getaj.net/AJE/index.m3u8",
          source: url,
          isLive: true, //是否为直播播放。
          skinLayout: [], //去除控制栏
        },
        function (player) {
          console.log("The player is created.");
        }
      );
    },
  },
  mounted() {},
  watch: {
    //监听视频地址、video的id值
    vData: {
      deep: true,
      immediate: true,
      handler(val) {
        if (val && val.cameraId) {
          this.videoId = val.cameraId;
          this.$nextTick(() => {
            this.getVideo(val.hlsurl, this.videoId);
          });
        }
      },
    },
  },
  beforeDestroy() {
    //  组件销毁时,清除播放器
    if (this.player) {
      this.player.dispose(); // 该方法会重置videojs的内部状态并移除dom
    }
  },
};
</script>

<style lang="scss" scoped>
//隐藏播放按钮
::v-deep .video-js .vjs-big-play-button {
  display: none;
}
</style>

组件调用:

<template>
  <!-- 接收 hls(.m3u8) 和 .hlv 的视频流 -->
  <!-- 视频页面 -->
  <div style="width: 100%; height: 100%">
    <BaseVideoFlv :vData="vData"></BaseVideoFlv>
  </div>
</template>

<script>
import BaseVideoMore from "./base_video_Flv.vue"; 

export default {
  name: "IndexVideo",
  components: {
    BaseVideoFlv,
  },
  data() {
    return {
      vData: {
        hlsurl: "",
        cameraId: "",
      },
    };
  },
  methods: {
    getUrlParam() {
      // 假数据
      this.vData = {
        hlsurl: "http://10.182.28.116:8080/live/00000011-0000-0000-0000-0a3b010b401f.flv",
        cameraId: "video_id_01",
      };
    },
  },
  created() {
    this.getUrlParam();
  },
};
</script>

<style lang="scss" scoped>
</style>

二、播放视频

web前端HTML播放HLS在线视频流(m3u8):
https://blog.csdn.net/Evil_0_0_0/article/details/105768336

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Windyluna

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值