欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue-video-player實(shí)現(xiàn)實(shí)時(shí)視頻播放方式(監(jiān)控設(shè)備-rtmp流)

 更新時(shí)間:2020年08月10日 11:08:27   作者:辣姐什么鬼  
這篇文章主要介紹了vue-video-player實(shí)現(xiàn)實(shí)時(shí)視頻播放方式(監(jiān)控設(shè)備-rtmp流),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

監(jiān)控設(shè)備播放效果如下

1、vue項(xiàng)目安裝vue-video-player

npm install vue-video-player --save

2、編寫視頻播放組件(放上完整的組件例子,父組件調(diào)用時(shí)給videoSrc和playerOptions.sources[0].src賦值就可以播放了,具體操作有注釋)

注:style樣式部分用了lang=scss,如果自己的項(xiàng)目沒用他請(qǐng)用自己的方式改一下樣式部分避免報(bào)錯(cuò)

 
<template>
  <div class="video-js">
   <div v-if="videoSrc===''" class="no-video">
    暫未播放視頻
   </div>
   <video-player v-else class="video-player vjs-custom-skin"
          ref="videoPlayer"
          :playsinline="true"
          :options="playerOptions">
   </video-player>
  </div>
</template>
 
<script>
import videojs from 'video.js'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
import {videoPlayer} from 'vue-video-player'
import 'videojs-flash'
import SWF_URL from 'videojs-swf/dist/video-js.swf'
 
videojs.options.flash.swf = SWF_URL // 設(shè)置flash路徑,Video.js會(huì)在不支持html5的瀏覽中使用flash播放視頻文件
export default {
 name: 'videojs',
 components: {
  videoPlayer
 },
 data () {
  return {
   videoSrc: '',
   playerOptions: {
    live: true,
    autoplay: true, // 如果true,瀏覽器準(zhǔn)備好時(shí)開始播放
    muted: false, // 默認(rèn)情況下將會(huì)消除任何音頻
    loop: false, // 是否視頻一結(jié)束就重新開始
    preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應(yīng)該開始下載視頻數(shù)據(jù)。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)
    aspectRatio: '16:9', // 將播放器置于流暢模式,并在計(jì)算播放器的動(dòng)態(tài)大小時(shí)使用該值。值應(yīng)該代表一個(gè)比例 - 用冒號(hào)分隔的兩個(gè)數(shù)字(例如"16:9"或"4:3")
    fluid: true, // 當(dāng)true時(shí),Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應(yīng)其容器。
    controlBar: {
     timeDivider: false,
     durationDisplay: false,
     remainingTimeDisplay: false,
     currentTimeDisplay: false, // 當(dāng)前時(shí)間
     volumeControl: false, // 聲音控制鍵
     playToggle: false, // 暫停和播放鍵
     progressControl: false, // 進(jìn)度條
     fullscreenToggle: true // 全屏按鈕
    },
    techOrder: ['flash'], // 兼容順序
    flash: {
     hls: {
      withCredentials: false
     },
     swf: SWF_URL
    },
    sources: [{
     type: 'rtmp/flv',
     src: '' // 視頻地址-改變它的值播放的視頻會(huì)改變
    }],
    notSupportedMessage: '此視頻暫無(wú)法播放,請(qǐng)稍后再試' // 允許覆蓋Video.js無(wú)法播放媒體源時(shí)顯示的默認(rèn)信息。
   }
  }
 }
}
</script>
 
<style scoped lang="less">
 .video-js{
  width:100%;
  height:100%;
  .no-video{
   display:flex;
   height:100%;
   font-size:14px;
   text-align:center;
   justify-content: center;
   align-items:center;
  }
 }
</style>
 
 
 

3、父組件調(diào)用視頻播放組件,點(diǎn)擊“播放視頻”替換組件里的視頻流地址播放實(shí)時(shí)視頻

<template>
 <div class="about">
  <video-player ref="playerObj"></video-player>
  <a @click="playVideo">播放視頻</a>
 </div>
</template>
<script>
 import VideoPlayer from './../../components/VideoPlayer'
 export default {
   name: 'about',
   components: {
     VideoPlayer
   },
   data() {
     return {}
 
   },
   methods: {
     playVideo() {
       this.$refs['playerObj'].videoSrc = 'rtmp://xxxxxxxx'
       this.$refs['playerObj'].playerOptions.sources[0].src = 'rtmp://xxxxxxxx'
     }
   }
 }
</script>

4、vue.config.js文件如下:需要加入的是chainwebpack配置

// vue.config.js
const path = require('path')
const webpack = require('webpack')
 
module.exports = {
 baseUrl: process.env.NODE_ENV === 'production' ? '/bcmp-web/' : '/',
 outputDir: process.env.NODE_ENV === 'production' ? 'bcmp-web' : 'dist',
 lintOnSave: true,
 productionSourceMap: false,
 
 devServer: {
  open: true,
  host: '0.0.0.0',
  port: 9005,
  https: false,
  hotOnly: false,
  proxy: null
 },
 configureWebpack: {
  plugins: [
   new webpack.ProvidePlugin({
    jQuery: 'jquery',
    $: 'jquery',
    'windows.jQuery': 'jquery'
   })
  ]
 },
 chainWebpack: config => {
  config.module
   .rule('swf')
   .test(/\.swf$/)
   .use('url-loader')
   .loader('url-loader')
   .options({
    limit: 10000
   })
 },
 
 pluginOptions: {
  'style-resources-loader': {
   preProcessor: 'scss',
   patterns: [
    path.resolve(__dirname, './src/assets/baseStyle/var.scss'),
    path.resolve(__dirname, './src/assets/baseStyle/mixin.scss')
   ]
  }
 }
}

目前vue-video-player版本5.0.2,測(cè)試可用

補(bǔ)充知識(shí):vue項(xiàng)目接入視頻監(jiān)控系列-------播放器的選擇

在智慧城市發(fā)展迅速的今天,視頻監(jiān)控接入web平臺(tái)的需求似乎成了不可或缺和潮流。博主準(zhǔn)備對(duì)自己開發(fā)視頻監(jiān)控項(xiàng)目的經(jīng)歷做個(gè)記錄,整理成一個(gè)系列的文章。

在前端發(fā)展迅速的今天,h5的出現(xiàn)讓在web平臺(tái)實(shí)現(xiàn)無(wú)插件播放似乎成了可能,但是video對(duì)于RTMP或者RTSP協(xié)議的視頻流卻無(wú)能為力,在這里向大家推薦一個(gè)播放器: LivePlayer,這是一家視頻公司封裝的一個(gè)播放器,可以免費(fèi)使用:說明文檔

(獲取的播放地址為后端配置服務(wù)后調(diào)用接口獲取的)

使用:

第一步: 安裝:

npm install @liveqing/liveplayer

npm i -D copy-webpack-plugin

第二步:引入:

在webpack.dev.conf.js中引入和聲明插件:

const CopyWebpackPlugin = require('copy-webpack-plugin')

在該文件夾下plugins中聲明插件new CopyWebpackPlugin

plugins: [
new CopyWebpackPlugin([

  { from: 'node_modules/@liveqing/liveplayer/dist/component/crossdomain.xml'},
  { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf'},
  { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/'}

])]

第三步:

在index.html中引入:<script type="text/javascript" src="./js/liveplayer-lib.min.js"></script>

路徑中的js為上面輸出的js地址

第四步:

引入使用組件:

<template>
 <div class="video">
  <el-button type="primary" size="mini" @click="getDeviceChanleData" icon="el-icon-search">選擇通道</el-button>
  <el-button type="primary" size="mini" @click="doStart" icon="el-icon-search">開始直播</el-button>
  <live-player :videoUrl="videoUrl" fluent autoplay live stretch></live-player>
 </div>
</template>
<script>
import LivePlayer from '@liveqing/liveplayer'
import {
 getDeviceList,
 getDeviceChanleList,
 start
} from './apis/index.js'
export default {
 data() {
  return {
   id: '',
   videoUrl: ''
  }
 },
 components: {
  LivePlayer
 },
 created() {
  this.getDeviceData()
 },
 methods: {
  // 獲取設(shè)備數(shù)據(jù)列表
  getDeviceData() {
   const para = {
    start: 1,
    limit: 10,
    online: true,
    q: ''
   }
   var par = {
    params: para
   }
   getDeviceList(par).then(res => {
    console.log('設(shè)備數(shù)據(jù)', res)
    this.id = res.DeviceList[0].ID
   })
  },
  // 查詢?cè)O(shè)備通道列表
  getDeviceChanleData() {
   const para = {
    serial: this.id
   }
   var par = {
    params: para
   }
   getDeviceChanleList(par).then(res => {
    console.log('設(shè)備通道數(shù)據(jù)', res)
   })
  },
  // 開始直播
  doStart() {
   const para = {
    serial: this.id
   }
   var par = {
    params: para
   }
   start(par).then(res => {
    console.log('開始直播', res)
    this.videoUrl = res.RTMP
    // this.videoUrl = res.HLS
    // this.videoUrl = res.FLV
   })
  }
 }
}
</script>
<style scoped>
.video{
 position: relative;
 width:500px;
 height:300px;
}
img{
 width:100%;
 height:100%;
}
.time1{
 position: absolute;
 top:13px;
 right:150px;
}
</style>

效果圖:

以上這篇vue-video-player實(shí)現(xiàn)實(shí)時(shí)視頻播放方式(監(jiān)控設(shè)備-rtmp流)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論