flvvideo.vue
5.24 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<template>
<div class="ocxbox">
<canvas id="video1" style="width:100%;height:100%;" class="fvideo"></canvas>
<div class="control" hidden>
<span :class="{'videostatus':true,'el-icon-video-play':videostatus,'el-icon-video-pause':!videostatus }" @click="controlvideo"></span>
<!-- <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>
var player;
export default {
data() {
return {
show: true,
videostatus:false,
furllstatus:false
};
},
computed: {},
methods: {
controlvideo() {
this.videostatus = !this.videostatus
if(!this.videostatus) {
this.startFunc()
} else {
this.stopFunc()
}
},
fullvideo(ev){
if(!this.furllstatus){
this.furllstatus = true;
this.fullel();
} else {
this.furllstatus = false;
this.exitFullscreen();
}
},
fullel(){
var ele = document.getElementById("full")
if (ele.requestFullscreen) {
ele.requestFullscreen();
} else if (ele.mozRequestFullScreen) {
ele.mozRequestFullScreen();
} else if (ele.webkitRequestFullScreen) {
ele.webkitRequestFullScreen();
}
},
exitFullscreen(){
var de = document
if (de.exitFullscreen) {
de.exitFullscreen();
} else if (de.mozCancelFullScreen) {
de.mozCancelFullScreen();
} else if (de.webkitCancelFullScreen) {
de.webkitCancelFullScreen();
}
},
startFunc(url) {
this.stopFunc()
/**
* 设置解密密码,必须是16字节
*/
player.setCryptoKey("");
/**
* 开始播放,参数为 http-flv或 websocket-flv 的url
*/
player.start(url);
},
stopFunc() {
/**
* 停止播放
*/
player.stop();
},
fullFunc() {
/**
* 全屏播放
*/
player.fullscreen();
},
volumeChange(event) {
/**
* 设置音量
* 0.0 ~~ 1.0
* 当为0.0时,完全静音, 最大1.0
*/
player.setVolume(event.target.value / 100.0);
},
bufferChange(event) {
player.setBufferTime(event.target.value);
},
scaleModeChange(event) {
/**
* 视频缩放模式, 当视频分辨率比例与Canvas显示区域比例不同时,缩放效果不同:
* 0 视频画面完全填充canvas区域,画面会被拉伸 --- 默认值
* 1 视频画面做等比缩放后,对齐Canvas区域,画面不被拉伸,但有黑边
* 2 视频画面做等比缩放后,完全填充Canvas区域,画面不被拉伸,没有黑边,但画面显示不全
* 软解时有效
*/
player.setScaleMode(event.target.value);
}
},
mounted() {
NodePlayer.load(() => {
/**
* 是否打印debug信息
*/
// NodePlayer.debug(true);
player = new NodePlayer();
/**
* 自动测试浏览器是否支持MSE播放,如不支持,仍然使用软解码。
* 紧随 new 后调用
* 不调用则只使用软解
*/
//player.useMSE();
/**
* 传入 canvas视图的id,当使用mse时,自动转换为video标签
*/
player.setView("video1");
/**
* 是否开启屏幕常亮
* 在手机浏览器上,canvas标签渲染视频并不会像video标签那样保持屏幕常亮
* 如果需要该功能, 可以调用此方法, 会有少量cpu消耗, pc浏览器不会执行
*/
player.setKeepScreenOn();
/**
* 设置为等比缩放模式
*/
player.setScaleMode(1);
/**
* 设置最大缓冲时长,单位毫秒,只在软解时有效
*/
player.setBufferTime(1000);
player.on("start", () => {
console.log("player on start");
});
player.on("stop", () => {
console.log("player on stop");
});
player.on("error", e => {
console.log("player on error", e);
});
player.on("videoInfo", (w, h) => {
console.log("player on video info width=" + w + " height=" + h);
});
player.on("audioInfo", (r, c) => {
console.log("player on audio info samplerate=" + r + " channels=" + c);
});
player.on("stats", stats => {
// console.log("player on stats=", stats);
});
player.on("metadata", metadata => {
var m = NodePlayer.AMF.parseScriptData(
metadata.buffer,
0,
metadata.length
);
console.log(m);
});
});
}
};
</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>