minhangChannel.vue
4.65 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
<template>
<div id="channelList" style="width: 100%">
<div class="page-header">
<div class="page-title">
<el-button icon="el-icon-back" size="mini" style="font-size: 20px; color: #000;" type="text"
@click="showDevice"></el-button>
<el-divider direction="vertical"></el-divider>
设备列表
</div>
</div>
<el-dialog title="视频播放" top="0" :close-on-click-modal="false" :visible.sync="showVideoDialog" @close="close()"
v-if="showVideoDialog">
<div style="width: 100%; height: 100%">
<!-- 使用video播放视频铺满 -->
<video ref="myVideo" autoplay controls width="100%" height="500" id="myVideo"></video>
</div>
</el-dialog>
<el-container style="height: 82vh;">
<el-main style="padding: 5px;">
<el-table ref="channelListTable" :data="deviceChannelList" :height="winHeight" style="width: 100%"
header-row-class-name="table-header">
<el-table-column prop="name" label="通道名称" min-width="180">
</el-table-column>
<el-table-column label="操作" width="100" fixed="right">
<template slot-scope="scope">
<el-button @click="handlerOnPlay(scope.row)" size="medium" icon="el-icon-video-play" type="text">播放
</el-button>
</template>
</el-table-column>
</el-table>
</el-main>
</el-container>
</div>
</template>
<script>
import flvjs from 'flv.js';
import MinhangService from "../service/MinhangService.js";
export default {
name: 'minhangChannel',
data() {
return {
videoUrl: "",
player: null,
hasAudio: false,
showVideoDialog: false,
minhangService: new MinhangService(),
deviceId: this.$route.params.deviceId,
deviceChannelList: [
{
channelId: 5,
name: "车前",
},
{
channelId: 3,
name: "驾驶舱"
},
{
channelId: 0,
name: "中门",
},
{
channelId: 4,
name: "前门"
},
{
channelId: 2,
name: "后车厢"
},
{
channelId: 7,
name: "右后视镜"
},
{
channelId: 6,
name: "倒车"
},
{
channelId: 1,
name: "前车箱"
},
],
online: "",
subStream: "",
winHeight: window.innerHeight - 200,
currentPage: 1,
count: 15,
total: 0,
};
},
mounted() {
this.initData();
},
destroyed() {
if (!this.player) return
this.player.pause()
this.player.unload()
this.player.detachMediaElement()
this.player.destroy()
this.player = null
},
methods: {
createdPlay() {
if (flvjs.isSupported()) {
// var videoDom = document.getElementById('myVideo')
console.log(this.videoUrl);
let videoDom = this.$refs.myVideo
// 创建一个播放器实例
var player = flvjs.createPlayer({
type: 'flv', // 媒体类型,默认是 flv,
isLive: true, // 是否是直播流
url: this.videoUrl // 流地址
}, {
// 其他的配置项可以根据项目实际情况参考 api 去配置
autoCleanupMinBackwardDuration: true, // 清除缓存 对 SourceBuffer 进行自动清理
})
player.attachMediaElement(videoDom)
player.load()
player.play()
this.player = player
}
},
showDevice() {
this.$router.push({ name: 'minhang' })
},
initData() {
},
handlerOnPlay(val) {
this.minhangService.onPlay(this.deviceId, val.channelId, (res => {
this.videoUrl = res.data
this.showVideoDialog = true
this.$nextTick(() => {
this.createdPlay()
})
}))
},
close() {
this.showVideoDialog = false
}
}
};
</script>
<style>
.videoList {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
}
.video-item {
position: relative;
width: 15rem;
height: 10rem;
margin-right: 1rem;
background-color: #000000;
}
.video-item-img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
height: 100%;
}
.video-item-img:after {
content: "";
display: inline-block;
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 3rem;
height: 3rem;
background-size: cover;
background-color: #000000;
}
.video-item-title {
position: absolute;
bottom: 0;
color: #000000;
background-color: #ffffff;
line-height: 1.5rem;
padding: 0.3rem;
width: 14.4rem;
}
</style>