vue实现flv格式视频播放效果

 更新时间:2023年07月28日 15:58:45   作者:浮桥  
这篇文章主要介绍了vue实现flv格式视频播放,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

公司项目需要实现摄像头实时视频播放,flv格式的视频。先百度使用flv.js插件实现,但是两个摄像头一个能放一个不能放,没有找到原因。(开始两个都能放,后端更改地址后不有一个不能放)但是在另一个系统上是可以播放的。使用的是jessibuca.js

jessibuca.js实现视频播放

1、下载jessibuca.js包

这三个文件需要直接放到public文件夹里,不能在添加文件夹放置。

2、创建VideoPlayer.vue文件

<template>
    <div id="container" ref="container"></div>
</template>
<script>
export default {
    name: 'DemoPlayer',
    props: {
        videoUrl: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            jessibuca: null,
            version: '',
            wasm: false,
            vc: 'ff',
            playing: false,
            quieting: true,
            loaded: false, // mute
            showOperateBtns: false,
            showBandwidth: false,
            err: '',
            speed: 0,
            performance: '',
            volume: 1,
            rotate: 0,
            useWCS: false,
            useMSE: true,
            useOffscreen: false,
            recording: false,
            recordType: 'webm',
            scale: 0
        }
    },
    mounted() {
        this.create()
        window.onerror = (msg) => (this.err = msg)
    },
    unmounted() {
        this.jessibuca.destroy()
    },
    methods: {
        create(options) {
            options = options || {}
            this.jessibuca = new window.Jessibuca(
                Object.assign(
                    {
                        container: this.$refs.container,
                        videoBuffer: 0.2, // Number(this.$refs.buffer.value), // 缓存时长
                        isResize: false,
                        useWCS: this.useWCS,
                        useMSE: this.useMSE,
                        text: '',
                        // background: "bg.jpg",
                        loadingText: '疯狂加载中...',
                        // hasAudio:false,
                        debug: true,
                        supportDblclickFullscreen: true,
                        showBandwidth: this.showBandwidth, // 显示网速
                        operateBtns: {
                            fullscreen: this.showOperateBtns,
                            screenshot: this.showOperateBtns,
                            play: this.showOperateBtns,
                            audio: this.showOperateBtns
                        },
                        vod: this.vod,
                        forceNoOffscreen: !this.useOffscreen,
                        isNotMute: true,
                        timeout: 10
                    },
                    options
                )
            )
            var _this = this
            this.jessibuca.on('pause', function () {
                console.log('on pause')
                _this.playing = false
            })
            this.jessibuca.on('play', function () {
                console.log('on play')
                _this.playing = true
            })
            this.jessibuca.on('mute', function (msg) {
                console.log('on mute', msg)
                _this.quieting = msg
            })
            this.jessibuca.on('error', function (error) {
                console.log('error', error)
            })
            this.jessibuca.on('performance', function (performance) {
                var show = '卡顿'
                if (performance === 2) {
                    show = '非常流畅'
                } else if (performance === 1) {
                    show = '流畅'
                }
                _this.performance = show
            })
            this.jessibuca.on('play', () => {
                this.playing = true
                this.loaded = true
                this.quieting = this.jessibuca.isMute()
            })
        },
        play(videoUrl) {
            if (videoUrl) {
                this.jessibuca.play(videoUrl)
            } else {
                // this.$message.error('播放地址出错')
                this.destroy()
            }
        },
        mute() {
            this.jessibuca.mute()
        },
        cancelMute() {
            this.jessibuca.cancelMute()
        },
        pause() {
            this.jessibuca.pause()
            this.playing = false
            this.err = ''
            this.performance = ''
        },
        destroy() {
            if (this.jessibuca) {
                this.jessibuca.destroy()
            }
            this.create()
            this.playing = false
            this.loaded = false
            this.performance = ''
        }
    }
}
</script>
<style>
#container {
    background: rgba(13, 14, 27, 0.7);
    width: 100%;
    height: 100%;
}
</style>

3、使用组件

引入

import VideoPlayer from '@/components/VideoPlayer.vue'

使用

<VideoPlayer ref="VideoPlayer"></VideoPlayer>

播放

let url = 'http://182.150.58.94:15280/rtp/44010200492000000001_34020000001320000110.flv'
this.$refs.VideoPlayer.play(url)

效果

参考文档:

jessibuca-api-文档

参考官方实例 jessibuca-vue-demo

vue中播放flv流视频

1、安装环境npm install video.jsnpm install flv.js

2、引入video,在main.js中引入

import videojs from "video.js";
import "video.js/dist/video-js.css";
Vue.prototype.$video = videojs;

在这里插入图片描述

3、在播放flv流视频代码如下

<template>
  <div class="wrapper">
    <video id="videoElement" controls autoplay muted width="800px" height="600px">
    </video>
    <button @click="play">播放</button>
  </div>
</template>
<script>
  import flvjs from "flv.js";
  export default {
    data() {
      return {
        player: null,
      }
    },
    mounted() {
        if (flvjs.isSupported()) {
          var videoElement = document.getElementById('videoElement');
          this.flvPlayer = flvjs.createPlayer({
            type: 'flv',
        isLive: true,
        hasAudio: false,
            url: 'http://192.168.1.212/hdl/hlsram/live1.flv'
          });
          this.flvPlayer.attachMediaElement(videoElement);
          this.flvPlayer.load();
      	  this.flvPlayer.play();
        }
    },
    methods: {
      play() {
        this.flvPlayer.play();
      }
    },
    beforeDestroy() {
      // 播放器存在清除播放器
      if (this.player) {
         this.player.destroy()
       }
    }
  }
</script>
<style scoped>
  .wrapper {
    width: 800px;
    height: 600px;
    margin: 100px 30px;
    overflow: hidden;
    position: relative;
  }
  .iframe {
    width: 1024px;
    height: 608px;
    position: absolute;
    top: -150px;
    left: -120px;
  }
</style>

效果图,本身电脑的原因存在延迟比较高

在这里插入图片描述

到此这篇关于vue实现flv格式视频播放的文章就介绍到这了,更多相关vue视频播放内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue+element实现表格新增、编辑、删除功能

    vue+element实现表格新增、编辑、删除功能

    这篇文章主要为大家详细介绍了vue+element实现表格新增、编辑、删除功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-05-05
  • vue中computed和watch的使用实例代码解析

    vue中computed和watch的使用实例代码解析

    这篇文章主要介绍了vue中computed和watch的综合运用实例,主要需求是点击按钮实现天气的切换效果结合示例代码给大家介绍的非常详细,需要的朋友可以参考下
    2022-04-04
  • 如何使用vue实现跨域访问第三方http请求

    如何使用vue实现跨域访问第三方http请求

    这篇文章主要介绍了如何使用vue实现跨域访问第三方http请求,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2024-03-03
  • 详解vue组件开发脚手架

    详解vue组件开发脚手架

    本篇文章给大家详细分析了vue组件开发脚手架的相关内容以及知识点,对此有兴趣的朋友可以学习参考下。
    2018-06-06
  • vue监听页面上的报错信息

    vue监听页面上的报错信息

    这篇文章主要介绍了vue监听页面上的报错信息,window.onerror和window.addEventListener(‘error‘)的区别,需要的朋友可以参考下
    2023-10-10
  • Vue.js 插件开发详解

    Vue.js 插件开发详解

    本文会通过一个简单的vue-toast插件,来帮助了解掌握插件的开发和使用。具有很好的参考价值,下面跟着小编一起来看下吧
    2017-03-03
  • uniapp引入模块化js文件和非模块化js文件的四种方式

    uniapp引入模块化js文件和非模块化js文件的四种方式

    这篇文章主要介绍了uniapp引入模块化js文件和非模块化js文件的四种方式,本文结合实例代码给大家讲解的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-11-11
  • 关于vue3 option api新玩法分享

    关于vue3 option api新玩法分享

    vue3新特性中最重要、内容最多的组合式api,组合式api既可以解决之前vue2开发的痛点,又提升了性能,下面这篇文章主要给大家介绍了关于vue3 option api新玩法的相关资料,需要的朋友可以参考下
    2022-06-06
  • vue-cli —— 如何局部修改Element样式

    vue-cli —— 如何局部修改Element样式

    这篇文章主要介绍了vue如何局部修改Element样式,帮助大家更好的理解和使用vue,感兴趣的朋友可以了解下
    2020-10-10
  • Vue监听属性和计算属性

    Vue监听属性和计算属性

    这篇文章主要介绍了Vue监听属性和计算属性,基本用法添加watch属性,值为一个对象。对象的属性名就是要监视的数据,属性值为回调函数,每当这个属性名对应的值发生变化,就会触发该回调函数执行,下面来看详细内容,需要的朋友也可以参考一下
    2021-12-12

最新评论