Browse Source

测试视频方法

lite
‘daijinzheng@xingtongworld.com’ 3 years ago
parent
commit
f60804fcbb
  1. 8
      src/api/home.js
  2. 62
      src/views/ty/index.vue
  3. 154
      src/views/ty/index2.vue

8
src/api/home.js

@ -56,3 +56,11 @@ export function allTsgInfoDatas(param) {
param,
})
}
export function allGetVideo(param) {
return request({
url: 'http://www.stadium.com/index.php?s=/api/video.video/getVideo',
method: 'post',
param,
})
}

62
src/views/ty/index.vue

@ -147,6 +147,9 @@ import * as echarts from "echarts";
import flvjs from "flv.js";
// api
import * as homeApi from '@/api/home'
// import Video from '../../components/btgym/Video.vue'
export default {
// components: {
@ -175,6 +178,7 @@ export default {
this.addNumber(0, 234098, 'insv')
this.addNumber(0, 234098, 'insv2')
this.addNumber(0, 234098, 'insv3')
this.getVideo()
// var videoElement1 = document.getElementById('myFlvVideo');
this.$nextTick(() => {
@ -746,83 +750,67 @@ export default {
}
},
createVideo() {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('myFlvVideo')
this.flvPlayer = flvjs.createPlayer(
{
type: 'flv',
isLive: true,
hasAudio: false,
url:
'rtsp://192.168.66.13:554/openUrl/MXdnCG4'
},
{
cors: true, //
enableWorker: true, // 线
enableStashBuffer: false, //
stashInitialSize: 128, // (kb) 384kb
autoCleanupSourceBuffer: true //
}
)
this.flvPlayer.attachMediaElement(videoElement)
this.flvPlayer.load()
// this.flvPlayer.play()
//
this.flvPlayer.on(flvjs.Events.ERROR, (errType, errDetail) => {
console.log('errorType:', errType)
console.log('errorDetail:', errDetail)
if (this.flvPlayer) {
this.destoryVideo()
this.createVideo()
}
})
}
},
getVideo() {
let that = this
console.log(that);
homeApi.allGetVideo().then(res => {
// get allTimeData
const tmpdata = res.data.returnData
console.log(tmpdata);
// this.day_num = tmpdata.day.noRepeatInNum
// this.week_num_num = tmpdata.week.noRepeatInNum
// this.mon_num = tmpdata.month.noRepeatInNum
// this.year_num = tmpdata.year.noRepeatInNum
// let btdata = new Array();
// let bvdata = new Array();
// tmpdata.foreach(function(item,index){
// console.log(item);
// console.log(index);
// });
});
},
destoryVideo() {
this.flvPlayer.pause()
this.flvPlayer.unload()
this.flvPlayer.detachMediaElement()
this.flvPlayer.destroy()
this.flvPlayer = null
}
},

154
src/views/ty/index2.vue

@ -0,0 +1,154 @@
<template>
<v-scale-screen width="1920" height="1080">
<div id="ty">
<div class="main">
<div class="center">
<div class="item">
<!-- <Video :src="src1" :poster="poster" /> -->
<!-- <video id="myFlvVideo" controls autoplay width="80%" height="200px"></video> -->
<video class="videosmall" ref="videosmallone" preload="auto" muted autoplay type="rtmp/flv">
<source src="" />
</video>
</div>
<div class="item">
<!-- <Video :src="src2" :poster="poster" /> -->
</div>
<div class="item">
<!-- <Video :src="src3" :poster="poster" /> -->
</div>
<!-- <div class="item"></div> -->
</div>
</div>
</div>
</v-scale-screen>
</template>
<script>
// echarts
// import * as echarts from "echarts";
import flvjs from "flv.js";
// api
// import * as homeApi from '@/api/home'
// import Video from '../../components/btgym/Video.vue'
export default {
// components: {
// Video
// },
data() {
return {
player: null,
};
},
mounted() {
// this.getVideo()
// var videoElement1 = document.getElementById('myFlvVideo');
// this.$nextTick(() => {
// this.createVideo()
// })
// this.createVideo()
this.init('rtsp://192.168.66.13:554/openUrl/MXdnCG4')
},
methods: {
// createVideo() {
// if (flvjs.isSupported()) {
// var videoElement = document.getElementById('myFlvVideo')
// console.log(videoElement);
// this.flvPlayer = flvjs.createPlayer(
// {
// type: 'flv',
// isLive: true,
// hasAudio: false,
// url:
// 'rtsp://192.168.66.13:554/openUrl/MXdnCG4'
// },
// {
// cors: true, //
// enableWorker: true, // 线
// enableStashBuffer: false, //
// stashInitialSize: 128, // (kb) 384kb
// autoCleanupSourceBuffer: true //
// }
// )
// this.flvPlayer.attachMediaElement(videoElement)
// this.flvPlayer.load()
// // this.flvPlayer.play()
// //
// // this.flvPlayer.on(flvjs.Events.ERROR, (errType, errDetail) => {
// // console.log('errorType:', errType)
// // console.log('errorDetail:', errDetail)
// // if (this.flvPlayer) {
// // this.destoryVideo()
// // this.createVideo()
// // }
// // })
// }
// },
init(val) { //val http://192.168.2.201:85/live/9311272c49b845baa2b2810ad9bf3f68.flv
setTimeout(() => { //使mountedDOM
var videoElement = this.$refs.videosmallone; // htmlvideo
if (flvjs.isSupported()) {
// playerTCP
if (this.player !== null) {
this.player.pause();
this.player.unload();
this.player.detachMediaElement();
this.player.destroy();
this.player = null;
}
this.player = flvjs.createPlayer( //DOM
{
type: "flv",
url: val, //url
isLive: true, //
hasAudio: false, //
hasVideo: true, //
enableStashBuffer: true, //
},
{
enableWorker: false, //线
enableStashBuffer: false, //IO
autoCleanupSourceBuffer: true, //
lazyLoad: false,
}
);
this.player.attachMediaElement(videoElement); //dom
this.player.load();//
//!!!!!!loadsettimeout this.player.play()
this.player.play();//
}
}, 1000);
},
// destoryVideo() {
// this.flvPlayer.pause()
// this.flvPlayer.unload()
// this.flvPlayer.detachMediaElement()
// this.flvPlayer.destroy()
// this.flvPlayer = null
// }
},
beforeUnmount() {
if (this.player) {
this.player.pause();
this.player.unload();
this.player.detachMediaElement();
this.player.destroy();
this.player = null;
}
},
// },
};
</script>
Loading…
Cancel
Save