LivePlayer播放器安装与使用

13 篇文章 0 订阅

LivePlayer播放器安装与使用


公司项目需要抛弃萤石云插件,因此视频播放要另寻出路,找来找去,找到了LiveGBS GB28181流媒体服务,研究了一下demo,因为要使用LivePlayer,所以想要在自己项目里使用,还得把LivePlayer装好,项目用的vue。

1、安装模块

npm install @liveqing/liveplayer

2、配置

在该文件中配置如下。
在这里插入图片描述

  externals: {
    'video.js': 'videojs',
    'flv.js': 'flvjs'
  },
plugins: [
    new CopyWebpackPlugin([
      { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/'},
      { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf'}
    ])
  ]

index.html增加

<script src="js/liveplayer-lib.min.js"></script>

3、使用

<template>
  <div id="app">
    <LivePlayer ref="player" :videoUrl="videoUrl" :snapUrl="snapUrl" :live="live" muted :hasaudio="hasAudio"></LivePlayer>
    <div @mouseup="ptzStop()">
      <label><input name="Fruit" type="radio" value="" @click="ptzControl('up')"/>FLV</label>
      <label><input name="Fruit" type="radio" value="" @click="change('up')"/>RTMP</label>
    </div>
    <div @mouseup="ptzStop()">
      <button @mousedown="ptzControl('up')"></button>
      <button @mousedown="ptzControl('down')"></button>
      <button @mousedown="ptzControl('left')"></button>
      <button @mousedown="ptzControl('right')"></button>
      <button @mousedown="ptzControl('up')"></button>
      <button @mousedown="ptzControl('right')">讲话</button>
      <button @mousedown="ptzControl('up')">放大</button>
      <button @mousedown="ptzControl('right')">缩小</button>
    </div>
  </div>
</template>

<script>

import LivePlayer from '@liveqing/liveplayer'
export default {
  name: 'HelloWorld',
  data () {
    return {
      hasAudio: '',
      videoUrl: '',
      protocol: '',
      videoTitle: '',
      snapUrl: '',
      serial: '',
      code: '',
      streamid: '',
      bRecording: '',
      streamInfo: {},
      msg: 'Welcome to Your Vue.js App',
      serial: '34020000001320000003',
      code: '34020000001320000001'
    }
  },
  props: {
    live: {
      type: Boolean,
      default: false
    }
  },
  components: {LivePlayer},
  mounted() {
    this.getSteram();
  },
  methods: {
    getSteram () {
      let params = {
        serial: this.serial,
        code: this.code
      }
      this.$http.get("/video/v1/stream/start", {
        params: params
      }).then(res => {
        let streamInfo = res.data || {};
        var videoUrl = this.isMobile() ? streamInfo.HLS : streamInfo.RTMP;

        var protocol = this.isMobile() ? "HLS" : "RTMP";
        if(this.flvSupported() && streamInfo.FLV) {
          videoUrl = streamInfo.FLV;
          protocol = "FLV";
        }
        this.hasAudio = streamInfo.AudioEnable && streamInfo.SourceAudioCodecName != "";
        this.videoUrl = videoUrl || "";
        this.protocol = protocol;
        this.videoTitle = 'title' || "";
        this.snapUrl = streamInfo.sn || "";
        this.serial = params.serial || "";
        this.code = params.code || "";
        this.streamid = streamInfo.StreamID || "";
        this.bRecording = streamInfo.RecordStartAt != ""
        this.streamInfo = streamInfo;
        }).catch(() => {
      })
    },

    /**
     * @name: 摄像头控制
     */
    ptzControl(type) {
      let params = {
        serial: this.serial,
        code: this.code,
        command: type
      }
      this.$http.get("/video/v1/control/ptz", {
        params: params
      }).then(res => {

      });
    },

    /**
     * @name: 停止
     */
    ptzStop() {
      let params = {
        serial: this.serial,
        code: this.code,
        command: 'stop'
      }
      this.$http.get("/video/v1/control/ptz", {
        params: params
      }).then(res => {

      });
    },

    /**
     * @name: 切换类型
     */
    ptzControl(type) {
      let params = {
        serial: this.serial,
        code: this.code,
        command: type
      }
      this.$http.get("/video/v1/control/ptz", {
        params: params
      }).then(res => {
        var protocol = this.isMobile() ? "HLS" : "RTMP";
        if(this.flvSupported() && streamInfo.FLV) {
          videoUrl = streamInfo.FLV;
          protocol = "FLV";
        }
        this.videoUrl = videoUrl || "";
      });
    },
  }
}
</script>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值