国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue + typescript + video.js實現 流媒體播放 視頻監控功能

2019-11-19 11:13:20
字體:
來源:轉載
供稿:網友

視頻才用流媒體,有后臺實時返回數據, 要支持flash播放, 所以需安裝對應的flash插件。當視頻播放時,每間隔3秒向后臺發送請求供檢測心跳,表明在線收看狀態,需要后臺持續發送視頻數據。

1. yarn add video.js videojs-flash

2. 創建videp.js聲明文件 

 

3. 創建video_player.vue組件,供外部調用。源碼如下

<script lang="ts">import { Component, Emit, Prop, Vue } from 'vue-property-decorator';import 'video.js/dist/video-js.css';import _videojs from 'video.js';const videojs = (window as any).videojs || _videojs;import 'videojs-flash';@Component({ name: 'video-player',})export default class VideoPlayer extends Vue { /* ------------------------ INPUT & OUTPUT ------------------------ */ @Prop({ type: Object, default: () => {}}) private options!: object; /* ------------------------ VUEX (vuex getter & vuex action) ------------------------ */ /* ------------------------ LIFECYCLE HOOKS (created & mounted & ...) ------------------------ */ private mounted() {  this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {   // console.log('onPlayerReady');  }); } private beforeDestroy() {  if (this.player) {   this.player.dispose();  } } /* ------------------------ COMPONENT STATE (data & computed & model) ------------------------ */ private player: any; /* ------------------------ WATCH ------------------------ */ /* ------------------------ METHODS ------------------------ */}</script><template><div class="module_video_player"> <video ref="videoPlayer" class="video-js" autoplay></video></div></template><style lang="stylus" scoped>@import '~@/assets/styles/var.styl';.module_video_player position relative width 780px</style>

4. 在需要使用的模塊(如show_monitor.vue)調用。組件創建后,向后臺發送輕輕獲取rtmp視頻播放地址,并更新videoOptions中的src。觸發video_player的創建、掛載等。

import VideoPlayer from '@/components/video_player.vue';components: { VideoPlayer,} private videoOptions = {  techOrder: ['flash', 'html5'],  sourceOrder: true,  flash: {   hls: { withCredentials: false },  },  html5: { hls: { withCredentials: false } },  sources: [{   type: 'rtmp/flv',   src: '', // 'rtmp://live.hkstv.hk.lxdns.com/live/hks2', // 香港衛視,可使用此地址測試  }],  autoplay: true,  controls: true,  width: '778',  height: '638', };<video-player :options="videoOptions" v-if="videoOptions.sources[0].src !== ''"></video-player>

5. 心跳檢測

在show_monitor.vue創建時,新建定時器,每隔3秒向后臺發送一個包含當前監控設備id的請求,告知后臺此設備監控被調用播放。show_monitor.vue銷毀時,清空定時器,后臺將停止傳輸視頻數據。

private intervalFunc: any;private created() { // **** this.intervalFunc = setInterval(() => {  EquipmentService.monitor_continue_test(this.eqmtid); }, 3000);}private destroyed() { clearInterval(this.intervalFunc);}

注: 可以再電腦安裝VLC media player下載 , 播放獲取到的rtmp路徑,已檢測數據獲取是否成功

總結

以上所述是小編給大家介紹的vue + typescript + video.js實現 流媒體播放 視頻監控功能,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳高县| 洛南县| 龙陵县| 南召县| 利辛县| 塔河县| 武穴市| 莱芜市| 聂荣县| 台北市| 鄂尔多斯市| 台北县| 新源县| 富蕴县| 青川县| 黄石市| 安化县| 长沙县| 丰台区| 尼玛县| 神农架林区| 甘肃省| 虞城县| 酒泉市| 阳朔县| 新昌县| 五峰| 利辛县| 大英县| 邓州市| 若羌县| 灵宝市| 凌云县| 汽车| 德化县| 永春县| 武邑县| 金平| 南郑县| 金塔县| 祁阳县|