videoDialog.vue
6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
<el-dialog :title="$t('dialog.video')" :visible.sync="isShow" v-if="isShow" :close-on-click-modal='false' class="manage-dialog dialog_lj" :before-close="closeDialog" width="1200px">
<div v-show="platform==1" class="video-box" style="height: 700px;" v-loading="loading">
<canvas id="canvas" style="background: black;width:100%;height:100%"></canvas>
</div>
<!-- poster="../../images/huiyi.jpg" -->
<div v-show="platform==2" style="height:'700px'" v-loading="loading">
<div id="my-video" style="background: black;width:100%;height:100%"></div>
<!-- <el-radio-group v-model="radio1" @change="radioChange">
<el-radio-button label="高清"></el-radio-button>
<el-radio-button label="流畅"></el-radio-button>
</el-radio-group> -->
<!-- <video style="height: 700px;width: 100%;" id="myVideo" class="video-js">
<source :src="palyUrl" type="application/x-mpegURL">
</video> -->
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="closeDialog" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
</div>
</el-dialog>
</template>
<script>
import EZUIKit from 'ezuikit-js'
// import videojs from 'video.js'
// import 'videojs-contrib-hls'
// import 'video.js/dist/video-js.css'
import SLPlayer from '../../../../static/js/slplayer'
export default {
data() {
return {
currObj:{
radio:1
},
radio1:'高清',
loading: true,
isShow: false,
Module:{},
player:'',
platform:'',
palyUrl:'',
playerM3u8:'',
playerM3u8Index:0,
playerEz:''
}
},
destroyed() {
if(this.platform == 1){
this.player.stop()
}else if(this.platform == 2){
if(this.playerEz){
let canvasVideo = document.getElementById('my-video')
canvasVideo.innerHTML = ''
}
// this.playerM3u8.dispose()
}
},
methods: {
radioChange(val){
this.currObj.radio = this.radio1=='高清'?'1':'2';
this.dialogInit(this.currObj)
},
dialogInit(row,val){
if(val){
this.playerM3u8Index = 0
this.radio1=='高清'
}
this.currObj = {
...row
}
let parmas = {
id:row.id
}
if(row.platform==2){
parmas.protocol=1
// parmas.quality = this.currObj.radio?this.currObj.radio:'1'
}
this.loading = true
this.$api.videoShopTourReport.getLiveAddress(parmas).then(data => {
let result = data.data;
if(result.code==200){
this.playVideo(result.data.liveAddress,row.platform,result.data.accessToken);
}
})
},
playVideo(row,platform,atoken) {
this.platform = platform
this.isShow = true;
this.loading = false
// this.createPlayer(row);
this.$nextTick(()=>{
if(this.platform==1){
this.createPlayer(row);
}else{
this.palyUrl= row
if(this.playerEz){
let canvasVideo = document.getElementById('my-video')
canvasVideo.innerHTML = ''
}
// 开始萤石云视频
this.playerEz = new EZUIKit.EZUIKitPlayer({
id: "my-video", // 视频容器ID
accessToken: atoken,
url: this.palyUrl,
template: 'simple',//simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版;
autoplay: true,
footer: ['hd','fullScreen'],
width: document.getElementById('my-video').offsetWidth - 20,
height:700,
});
// if(this.playerM3u8Index>0){
// setTimeout(()=>{
// if(this.playerM3u8){
// this.playerM3u8.src({
// src:this.palyUrl,
// type:'application/x-mpegURL'
// })
// this.playerM3u8.load()
// }
// },1000)
// }else{
// setTimeout(()=>{
// this.playerM3u8Index++;
// this.playerM3u8 = videojs(document.getElementById('myVideo'), { //播放的事件
// textTrackDisplay: false,
// posterImage: false,
// muted: false,
// controls: true,
// autoplay:true,
// preload:'auto',
// hls: {
// withCredentials: true
// },
// controlBar:{
// fullscreenToggle :false,
// pictureInPictureToggle: false,
// }
// },function(){
// console.log('视频可以播放了',this)
// })
// },1000)
// }
}
})
},
createPlayer(row) {
let that = this;
that.Module = {
/* ************************************ */
// 定义视频画布
canvas: document.getElementById("canvas"),
/* ************************************ */
// 设置相应的事件回调
onStart: function () {
console.log("onStart...")
},
onEnd: function () {
console.log("onEnd...")
},
onError: function (code, err) {
alert('error: ', code, err)
console.log('error: ', code, err);
},
onVideoStart: function () {
console.log('onVideoStart。。。');
},
// 录像回放中返回时间刻度
onPlayTime: function (ts) {
if(ts==0) return;
var date = new Date(ts * 1000);//如果date为10位不需要乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
var timestamp = Y + M + D + h + m + s;
}
}
SLPlayer(that.Module).then(function (obj) {
that.loading = false
that.player = obj;
setTimeout(()=>{
console.log(111)
that.player.start(row)
},1000)
});
},
closeDialog() {
if(this.platform == 1){
this.player.stop()
}else if(this.platform == 2){
// this.playerM3u8.dispose()
if(this.playerEz){
let canvasVideo = document.getElementById('my-video')
canvasVideo.innerHTML = ''
}
}
this.isShow = false;
}
}
}
</script>