flvvideo.vue
3.46 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
<template>
<div class="ocxbox">
<video id="flvvideo" autoplay style="width: 100%; height: 100%" class="fvideo"></video>
<div class="control" hidden>
<!-- <span :class="{'el-icon-full-screen':!furllstatus,'el-icon-circle-close':furllstatus,'videostatus':true, 'full-icon':true}" @click="fullvideo" id="full"></span> -->
</div>
</div>
</template>
<script>
export default {
data() {
return {
show: true,
videostatus: false,
furllstatus: false,
cururl:"",
player: "",
};
},
computed: {},
methods: {
initflv() {
if (flvjs.isSupported()) {
this.player = flv.createPlayer({
type: "flv",
});
}
},
startFunc(url) {
let playerel = document.getElementById("flvvideo");
if(this.player) {
this.destoryVideo(this.player);
}
this.cururl = url;
this.player = flvjs.createPlayer({
type: "flv",
isLive: true,
hasAudio: false,
url: url,
},{
enableWorker: false, //不启用分离线程
enableStashBuffer: false, //关闭IO隐藏缓冲区
reuseRedirectedURL: true, //重用301/302重定向url,用于随后的请求,如查找、重新连接等。
autoCleanupSourceBuffer: true //自动清除缓存
});
this.player.attachMediaElement(playerel);
this.player.load();
setTimeout(() => {
this.player.play();
}, 500);
this.player.on(flvjs.Events.ERROR, (errType, errDetail) => {
// alert("网络波动,正在尝试连接中...");
if (this.player) {
this.reloadVideo(this.player);
}
// errType是 NetworkError时,对应errDetail有:Exception、HttpStatusCodeInvalid、ConnectingTimeout、EarlyEof、UnrecoverableEarlyEof
// errType是 MediaError时,对应errDetail是MediaMSEError 或MEDIA_SOURCE_ENDED
});
this.player.on("statistics_info", (res)=> {
if (this.lastDecodedFrame == 0) {
this.lastDecodedFrame = res.decodedFrames;
return;
}
if (this.lastDecodedFrame != res.decodedFrames) {
this.lastDecodedFrame = res.decodedFrames;
} else {
this.lastDecodedFrame = 0;
if (this.player) {
this.reloadVideo(this.player)
}
}
});
//2000毫秒执行一次
},
flv_start() {
this.player.play();
},
reloadVideo(flvPlayer) {
this.destoryVideo(flvPlayer);
this.startFunc(this.cururl);
},
destoryVideo(flvPlayer) {
flvPlayer.pause();
flvPlayer.unload();
flvPlayer.detachMediaElement();
flvPlayer.destroy();
flvPlayer = null;
this.player = null;
},
flv_pause() {
this.player.pause();
},
},
mounted() {},
destroyed(){
if(this.player) {
this.destoryVideo(this.player)
}
}
};
</script>
<style lang="stylus">
.ocxbox {
height: 100%;
position: relative;
.fvideo {
height: 100%;
width: 100%;
}
.control {
position: absolute;
bottom: 0;
height: 40px;
width: 100%;
background: rgba(255, 255, 255, 0.2);
display: none;
.videostatus {
cursor: pointer;
color: #fff;
font-size: 30px;
line-height: 40px;
padding-left: 10px;
}
.full-icon {
float: right;
margin-right: 20px;
font-size: 25px;
}
}
}
.ocxbox:hover {
.control {
// display block
cursor: pointer;
}
}
</style>