vue实现flv格式视频播放

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

jessibuca.js实现视频播放

1、下载jessibuca.js包

在这里插入图片描述
这三个文件需要直接放到public文件夹里,不能在添加文件夹放置。

2、index.html文件引入jessibuca

<script src="/jessibuca.js"></script>

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、使用组件

  1. 引入
import VideoPlayer from '@/components/VideoPlayer.vue'
  1. 使用
<VideoPlayer ref="VideoPlayer"></VideoPlayer>
  1. 播放
let url = 'http://182.150.58.94:15280/rtp/44010200492000000001_34020000001320000110.flv'
this.$refs.VideoPlayer.play(url)

效果

在这里插入图片描述

参考文档:

jessibuca-api-文档
参考官方实例 jessibuca-vue-demo

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
Vue中下载FLV格式视频,你可以使用以下步骤: 1. 安装flv.js:flv.js是一个JavaScript库,用于在浏览器中播放FLV格式视频。你可以通过npm安装它,使用以下命令: ``` npm install flv.js --save ``` 2. 导入flv.js:在Vue组件中,你需要将flv.js导入到项目中。你可以使用以下代码: ``` import flvjs from 'flv.js' ``` 3. 创建FLV视频播放器:你可以在Vue组件中创建一个FLV视频播放器,使用以下代码: ``` <video ref="videoPlayer" controls></video> ``` 4. 初始化FLV视频播放器:在Vue组件的mounted钩子函数中,你需要初始化FLV视频播放器,使用以下代码: ``` mounted() { if (flvjs.isSupported()) { const videoElement = this.$refs.videoPlayer const flvPlayer = flvjs.createPlayer({ type: 'flv', url: 'your_video_url.flv' }) flvPlayer.attachMediaElement(videoElement) flvPlayer.load() flvPlayer.play() } } ``` 在上面的代码中,你需要将“your_video_url.flv”替换为你要下载的FLV视频的URL。 5. 添加下载按钮:你可以在Vue组件中添加一个下载按钮,使用以下代码: ``` <button @click="downloadVideo">下载视频</button> ``` 6. 实现下载功能:在Vue组件的methods中,你需要实现下载功能,使用以下代码: ``` downloadVideo() { const videoUrl = 'your_video_url.flv' const link = document.createElement('a') link.href = videoUrl link.download = 'video.flv' document.body.appendChild(link) link.click() document.body.removeChild(link) } ``` 在上面的代码中,你需要将“your_video_url.flv”替换为你要下载的FLV视频的URL,并将下载的视频命名为“video.flv”。 这样,你就可以在Vue中下载FLV格式视频了。请注意,下载视频可能涉及版权问题,请确保你有权下载并使用视频

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值