-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-player-zdy.html
615 lines (552 loc) · 24.9 KB
/
video-player-zdy.html
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./css/iconfont.css">
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #0f0f1e;
}
ul,
li,
ol {
list-style: none;
}
.main {
width: 1200px;
margin: 150px auto;
display: flex;
}
.main>.video-list {
background-color: #2329315c;
width: 18%;
min-width: 150px;
/* border: 1px solid red; */
}
.main>.video-list>ul {
padding-top: 10px;
padding-left: 5px;
}
.main>.video-list>ul>li {
float: left;
margin: 5px;
}
.main>.video-list>ul>li>a {
background-color: #607d8b47;
/* margin: 3px 8px; */
padding: 5px 10px;
font-size: 12px;
border-radius: 5px;
color: #eee;
text-decoration: none;
}
.main>.video-list>ul>li>a:hover {
color: #fdf751;
}
.main>.video-list>.title {
color: #fdf751;
position: relative;
border-bottom: 1px solid #434145;
box-sizing: border-box;
padding: 0px 12px;
height: 40px;
line-height: 40px
}
.main>.video-list>.title>span.line {
width: 50px;
height: 4px;
background-color: #fdf751;
position: absolute;
bottom: -2px;
left: 19px;
}
.main>.video-list.hidden {
display: none;
}
/* ------------------- */
.player-wrap {
width: 82%;
min-width: 600px;
/* margin: 50px auto; */
position: relative;
overflow: hidden;
z-index: 999;
}
.player-wrap.webfullscreen {
position: fixed;
top: 0;
left: 0;
display: flex;
align-items: center;
}
/* .player-wrap.active {
width: 100%;
} */
.player-wrap>video {
display: block;
width: 100%;
height: 553.5px;
}
.player-control-mask-wrap {
padding: 0 10px;
box-sizing: border-box;
width: 100%;
position: absolute;
bottom: 0;
background-color: rgba(211, 56, 56, 0.01);
}
.player-control-mask {
width: 100%;
/* height: 50px; */
}
.player-control-mask>.progress-top {
width: 100%;
}
.player-control-mask>.progress-top {
position: relative;
}
.player-control-mask>.progress-top>.progress-all {
width: 100%;
height: 4px;
background-color: #fff;
cursor: pointer;
}
.player-control-mask>.progress-top>.progress-current {
position: absolute;
top: 0;
left: 0;
width: 0%;
height: 4px;
background-color: rgba(0, 174, 236, 1);
cursor: pointer;
}
.player-control-mask>.progress-top>.progress-current>.progress-circle {
position: absolute;
width: 20px;
top: -8px;
/*
设置18px 的原因: 小电视的宽度是 20px,实际空白还有2px
我们让小电视一直处于当前进度条的最右侧定位 ,
当 progress-current 为 0 时, right:-18px; 要刚好抵消小电视的宽度,避免小电视图标
从左侧溢出来
*/
right: -9px;
cursor: pointer;
}
/* 鼠标移出时隐藏进度条小电视机 */
.player-control-mask>.progress-top>.progress-current>.progress-circle.hidden {
display: none;
}
.player-control {
height: 46px;
/* background-color: rgba(38, 52, 57, 0.03); */
display: flex;
align-items: center;
justify-content: space-between;
font-size: 12px;
}
/* 鼠标移出时隐藏控制按钮 */
.player-control.hidden {
display: none;
}
.player-control>.left {
width: 150px;
display: flex;
align-items: center;
justify-content: space-between;
margin-left: 10px;
}
.player-control>.right {
width: 400px;
display: flex;
justify-content: space-between;
align-items: center;
margin-right: 10px;
}
.player-control>.right>div,
.player-control>.left>div {
color: #ddd;
cursor: pointer;
padding: 3px 6px;
}
.player-control>.right>div:hover {
color: #fff;
}
.play_pause>i,
.volumn>i {
cursor: pointer;
color: #fff;
font-size: 30px;
}
.clearfix::after{
content: '';
display: block;
clear: both;
}
</style>
</head>
<body>
<div class="main">
<div class="player-wrap">
<video src="./video/0001-0250.mkv"></video>
<div class="player-control-mask-wrap">
<div class="player-control-mask">
<div class="progress-top">
<div class="progress-all"></div>
<div class="progress-current">
<div class="progress-circle">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" width="18" height="18"
preserveAspectRatio="xMidYMid meet"
style="width: 100%; height: 100%; transform: translate3d(0px, 0px, 0px);">
<defs>
<clipPath id="__lottie_element_1403">
<rect width="18" height="18" x="0" y="0"></rect>
</clipPath>
</defs>
<g clip-path="url(#__lottie_element_1403)">
<g transform="matrix(0.9883429408073425,-0.7275781631469727,0.6775955557823181,0.920446515083313,7.3224687576293945,-0.7606706619262695)"
opacity="1" style="display: block;">
<g opacity="1"
transform="matrix(0.9937776327133179,-0.11138220876455307,0.11138220876455307,0.9937776327133179,-2.5239999294281006,1.3849999904632568)">
<path fill="rgb(51,51,51)" fill-opacity="1"
d=" M0.75,-1.25 C0.75,-1.25 0.75,1.25 0.75,1.25 C0.75,1.663925051689148 0.4139249920845032,2 0,2 C0,2 0,2 0,2 C-0.4139249920845032,2 -0.75,1.663925051689148 -0.75,1.25 C-0.75,1.25 -0.75,-1.25 -0.75,-1.25 C-0.75,-1.663925051689148 -0.4139249920845032,-2 0,-2 C0,-2 0,-2 0,-2 C0.4139249920845032,-2 0.75,-1.663925051689148 0.75,-1.25z">
</path>
</g>
</g>
<g transform="matrix(1.1436611413955688,0.7535901665687561,-0.6317168474197388,0.9587040543556213,16.0070743560791,2.902894973754883)"
opacity="1" style="display: block;">
<g opacity="1"
transform="matrix(0.992861807346344,0.1192704513669014,-0.1192704513669014,0.992861807346344,-2.5239999294281006,1.3849999904632568)">
<path fill="rgb(51,51,51)" fill-opacity="1"
d=" M0.75,-1.25 C0.75,-1.25 0.75,1.25 0.75,1.25 C0.75,1.663925051689148 0.4139249920845032,2 0,2 C0,2 0,2 0,2 C-0.4139249920845032,2 -0.75,1.663925051689148 -0.75,1.25 C-0.75,1.25 -0.75,-1.25 -0.75,-1.25 C-0.75,-1.663925051689148 -0.4139249920845032,-2 0,-2 C0,-2 0,-2 0,-2 C0.4139249920845032,-2 0.75,-1.663925051689148 0.75,-1.25z">
</path>
</g>
</g>
<g transform="matrix(1,0,0,1,8.890999794006348,8.406000137329102)" opacity="1"
style="display: block;">
<g opacity="1"
transform="matrix(1,0,0,1,0.09099999815225601,1.1009999513626099)">
<path fill="rgb(255,255,255)" fill-opacity="1"
d=" M7,-3 C7,-3 7,3 7,3 C7,4.379749774932861 5.879749774932861,5.5 4.5,5.5 C4.5,5.5 -4.5,5.5 -4.5,5.5 C-5.879749774932861,5.5 -7,4.379749774932861 -7,3 C-7,3 -7,-3 -7,-3 C-7,-4.379749774932861 -5.879749774932861,-5.5 -4.5,-5.5 C-4.5,-5.5 4.5,-5.5 4.5,-5.5 C5.879749774932861,-5.5 7,-4.379749774932861 7,-3z">
</path>
<path stroke-linecap="butt" stroke-linejoin="miter" fill-opacity="0"
stroke-miterlimit="4" stroke="rgb(51,51,51)" stroke-opacity="1"
stroke-width="1.5"
d=" M7,-3 C7,-3 7,3 7,3 C7,4.379749774932861 5.879749774932861,5.5 4.5,5.5 C4.5,5.5 -4.5,5.5 -4.5,5.5 C-5.879749774932861,5.5 -7,4.379749774932861 -7,3 C-7,3 -7,-3 -7,-3 C-7,-4.379749774932861 -5.879749774932861,-5.5 -4.5,-5.5 C-4.5,-5.5 4.5,-5.5 4.5,-5.5 C5.879749774932861,-5.5 7,-4.379749774932861 7,-3z">
</path>
</g>
</g>
<g transform="matrix(1,0,0,1,8.89900016784668,8.083999633789062)" opacity="1"
style="display: block;">
<g opacity="1"
transform="matrix(1,0,0,1,-2.5239999294281006,1.3849999904632568)">
<path fill="rgb(51,51,51)" fill-opacity="1"
d=" M0.875,-1.125 C0.875,-1.125 0.875,1.125 0.875,1.125 C0.875,1.607912540435791 0.48291251063346863,2 0,2 C0,2 0,2 0,2 C-0.48291251063346863,2 -0.875,1.607912540435791 -0.875,1.125 C-0.875,1.125 -0.875,-1.125 -0.875,-1.125 C-0.875,-1.607912540435791 -0.48291251063346863,-2 0,-2 C0,-2 0,-2 0,-2 C0.48291251063346863,-2 0.875,-1.607912540435791 0.875,-1.125z">
</path>
</g>
</g>
<g transform="matrix(1,0,0,1,14.008999824523926,8.083999633789062)" opacity="1"
style="display: block;">
<g opacity="1"
transform="matrix(1,0,0,1,-2.5239999294281006,1.3849999904632568)">
<path fill="rgb(51,51,51)" fill-opacity="1"
d=" M0.8999999761581421,-1.100000023841858 C0.8999999761581421,-1.100000023841858 0.8999999761581421,1.100000023841858 0.8999999761581421,1.100000023841858 C0.8999999761581421,1.596709966659546 0.4967099726200104,2 0,2 C0,2 0,2 0,2 C-0.4967099726200104,2 -0.8999999761581421,1.596709966659546 -0.8999999761581421,1.100000023841858 C-0.8999999761581421,1.100000023841858 -0.8999999761581421,-1.100000023841858 -0.8999999761581421,-1.100000023841858 C-0.8999999761581421,-1.596709966659546 -0.4967099726200104,-2 0,-2 C0,-2 0,-2 0,-2 C0.4967099726200104,-2 0.8999999761581421,-1.596709966659546 0.8999999761581421,-1.100000023841858z">
</path>
</g>
</g>
</g>
</svg>
</div>
</div>
</div>
<div class="player-control">
<div class="left">
<div class="play_pause">
<i class="iconfont icon-bofang"></i>
</div>
<div class="timeinfo">
<span class="current_">00:00</span>
<span>/</span>
<span class="duration_">00:00</span>
</div>
</div>
<div class="right">
<div class="definition">
<span>1080P高清</span>
</div>
<div class="speed">
<span>倍速</span>
</div>
<div class="widescreen">
<span>宽屏</span>
</div>
<div class="pip">
<span>画中画</span>
</div>
<div class="pagefullscreen">
<span>网页全屏</span>
</div>
<div class="fullscreen">
<span>全屏</span>
</div>
<div class="volumn">
<i class="iconfont icon-shengyin_shiti"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="video-list">
<div class="title">
<span>视频列表</span>
<span class="line"></span>
</div>
<ul>
<li><a href="javascript:void(0);">第01集</a></li>
<li><a href="javascript:void(0);">第02集</a></li>
<li><a href="javascript:void(0);">第03集</a></li>
</ul>
</div>
</div>
<script>
const main = document.querySelector('.main')
const player_wrap = document.querySelector('.player-wrap')
const video = document.querySelector('video')
const player_control = document.querySelector('.player-control')
const play_pause = document.querySelector('.player-control >.left> .play_pause')
let progress_all = document.querySelector('.progress-all')
const progress_top = document.querySelector('.progress-top')
const progress_current = document.querySelector('.progress-current')
const progress_circle = document.querySelector('.progress-circle')
// 时长元素
const current_ = document.querySelector('.current_')
const duration_ = document.querySelector('.duration_')
// 画中画
const pip = document.querySelector('.pip')
// 选集 事件委托
const ul = document.querySelector('.video-list>ul')
// 宽屏
const widescreen = document.querySelector('.widescreen')
const video_list = document.querySelector('.video-list')
// 全屏
const fullscreen = document.querySelector('.fullscreen')
// 网页全屏
const pagefullscreen = document.querySelector('.pagefullscreen')
// 视频总时长
let duration = 0
// 能否拖拽
let flag = false
// pip是否进入了画中画
let flag_pip = false
// 是否宽屏
let flag_widescreen = false
// 是否网页全屏
let flag_pagefullscreen = false
let player_wrap_width = getComputedStyle(player_wrap).width
// video 必须要指定高度,要不然有偏差
let player_wrap_height = getComputedStyle(player_wrap).height
// console.log(player_wrap_width,player_wrap_height)
// 进度条总长度, 因为小电视图标向右偏移了18px,我们这里减去这个偏移量,避免图标溢出视频区域
let progress_all_width = parseInt(getComputedStyle(progress_all).width)
// 进度条的左偏移量
let offsetLeft_progress = player_wrap.offsetLeft
// 播放暂停按钮切换
play_pause.addEventListener('click', togglePlayPause)
video.addEventListener('click', togglePlayPause)
video.addEventListener('canplay', function () {
duration = this.duration
duration_.innerText = formatTime(duration)
})
video.addEventListener('timeupdate', function () {
// currentTime 时间更新
current_.innerText = formatTime(this.currentTime)
// 进度条随播放时间变化
const current = video.currentTime
const w = current / duration * progress_all_width
progress_current.style.width = w + 'px'
// 播放暂停图标切换,进入画中画模式后适用
if (video.paused) {
play_pause.firstElementChild.classList.add('icon-bofang')
play_pause.firstElementChild.classList.remove('icon-zanting2')
} else {
play_pause.firstElementChild.classList.add('icon-zanting2')
play_pause.firstElementChild.classList.remove('icon-bofang')
}
})
// 进度条点击
progress_top.addEventListener('mousedown', function (e) {
flag = true
currentTimeUpdate(e)
})
// 进度条拖拽
progress_circle.addEventListener('mousedown', function (e) {
// 可以开始进度条拖拽
flag = true
})
document.addEventListener('mouseup', function () {
// 取消进度条拖拽
flag = false
})
document.addEventListener('mousemove', currentTimeUpdate)
// 鼠标移出视频区域,隐藏遮罩层
player_wrap.addEventListener('mouseout', function () {
// 视频在播放时移出鼠标才会隐藏控制按钮
if (video.paused) return
progress_circle.classList.add('hidden')
player_control.classList.add('hidden')
})
player_wrap.addEventListener('mouseover', function () {
progress_circle.classList.remove('hidden')
player_control.classList.remove('hidden')
})
// 屏幕尺寸改变时从新获取一些变量
document.onresize = function () {
offsetLeft_progress = player_wrap.offsetLeft
}
// 画中画
pip.addEventListener('click', function () {
// 进入画中画
if (!flag_pip) {
video.requestPictureInPicture()
} else {
// 退出画中画
document.exitPictureInPicture()
}
})
// 进入画中画模式触发
video.addEventListener('enterpictureinpicture', function () {
flag_pip = true
})
// 退出画中画模式触发
video.addEventListener('leavepictureinpicture', function () {
flag_pip = false
})
// 选集
ul.addEventListener('click', e => {
e = e || window.event
const target = e.target || e.srcElement
if (target.nodeName === 'A') {
const text = target.innerText
if (text.includes('1')) {
video.src = './video/0001-0250.mkv'
}
if (text.includes('2')) {
video.src = './video/0001-0475.mkv'
}
if (text.includes('3')) {
video.src = './video/hzw.mp4'
}
}
})
// 宽屏
widescreen.addEventListener('click', function () {
console.log('flag_pagefullscreen',flag_pagefullscreen)
if(flag_pagefullscreen) return
console.log('over',flag_pagefullscreen)
// 开启宽屏 ,不在网页全屏下
if (!flag_widescreen ) {
video_list.classList.add('hidden')
// player_wrap.classList.add('active')
player_wrap.style.width = '100%'
progress_all_width = parseInt(getComputedStyle(progress_all).width)
flag_widescreen = true
} else {
// 退出宽屏
video_list.classList.remove('hidden')
// player_wrap.classList.remove('active')
player_wrap.style.width = '82%'
progress_all_width = parseInt(getComputedStyle(progress_all).width)
flag_widescreen = false
}
})
// 全屏
fullscreen.addEventListener('click', function () {
video.requestFullscreen()
})
// 网页全屏
pagefullscreen.addEventListener('click', function () {
if (!flag_pagefullscreen) {
// 浏览器尺寸
const clientW = document.documentElement.clientWidth
const clientH = document.documentElement.clientHeight
console.log(clientW,clientH)
player_wrap.classList.add('webfullscreen')
player_wrap.style.width = clientW + 'px'
player_wrap.style.height = clientH + 'px'
player_wrap.style.backgroundColor = '#000'
video.style.height = clientH + 'px'
flag_pagefullscreen = true
}else {
// 退出网页全屏
// video_list.classList.remove('hidden')
if(flag_widescreen){
player_wrap.style.width = '100%'
}else{
player_wrap.style.width = '82%'
}
video.style.height = player_wrap_height
player_wrap.style.height = player_wrap_height
player_wrap.classList.remove('webfullscreen')
flag_pagefullscreen = false
}
})
function togglePlayPause() {
play_pause.firstElementChild.classList.toggle('icon-zanting2')
play_pause.firstElementChild.classList.toggle('icon-bofang')
if (video.paused) {
video.play()
} else {
video.pause()
}
}
function currentTimeUpdate(e) {
if (!flag) return
// console.log(e.pageX, offsetLeft_progress)
// 进度条前进的像素,不能超过 progress-all 的宽度
let d = e.pageX - offsetLeft_progress
if (d < 0) d = 0
if (d > progress_all_width) d = progress_all_width
// circle 里面小电视的宽度差不多是 18 px
progress_current.style.width = d + 'px'
// 改变视频currenttime
video.currentTime = d / progress_all_width * duration
current_.innerText = formatTime(video.currentTime)
}
// 阻止遮罩层文本选中
// 格式化时间
function formatTime(second) {
const m = parseInt(second / 60)
if (m < 100) {
const s = parseInt(second % 60)
return (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s)
}
}
</script>
<script>
/*
梳理下功能点
1. 点击播放图标和暂停图标完成播放和暂停,并完成图标切换
2. 总时长和当前时长显示
3. 进度条随着播放时长改变
4. 进度条可以拖拽,拖拽时完成进度条显示变化,以及播放currentTime的变化
5. 进度条可以点击,完成当前播放位置的切换
6. 阻止遮罩层文字选中
7. 画中画模式的开启和关闭
8. 宽屏模式
9. 网页全屏
10. 全屏
11. 手机端全屏时横屏, 横屏时全屏
补充:
12. 当时拍在播放 移出时 隐藏 player-control ,并且进度条不显示小电视图标
*/
</script>
</body>
</html>