Skip to content

Commit 0ded83a

Browse files
committed
before watch video
1 parent 2bbb4a6 commit 0ded83a

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

11 Custom Video Player/index.html

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>HTML Video Player</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
<div class="player">
11+
<video class="player__video viewer" src="https://player.vimeo.com/external/194837908.sd.mp4?s=c350076905b78c67f74d7ee39fdb4fef01d12420&profile_id=164"></video>
12+
13+
<div class="player__controls">
14+
<div class="progress">
15+
<div class="progress__filled"></div>
16+
</div>
17+
<button class="player__button toggle" title="Toggle Play"></button>
18+
<input type="range" name="volume" class="player__slider" min="0" max="1" step="0.05" value="0.1">
19+
<input type="range" name="playbackRate" class="player__slider" min="0.5" max="2" step="0.1" value="1">
20+
<button data-skip="-10" class="player__button">« 10s</button>
21+
<button data-skip="25" class="player__button">25s »</button>
22+
</div>
23+
</div>
24+
25+
<script src="scripts.js"></script>
26+
</body>
27+
</html>

11 Custom Video Player/scripts.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function switchPlayAndPause() {
2+
const ctrl = document.querySelector('.player__button');
3+
4+
if(video_application.paused) {
5+
video_application.play();
6+
ctrl.textContent = '>';
7+
}
8+
else {
9+
video_application.pause();
10+
ctrl.textContent = '||';
11+
}
12+
}
13+
14+
15+
//click view play and pause
16+
const video_application = document.querySelector('.player__video');
17+
video_application.addEventListener('click', switchPlayAndPause);
18+
19+
//play button
20+
const play_or_pause_ctrl = document.querySelector('.player__button');
21+
play_or_pause_ctrl.addEventListener('click', switchPlayAndPause);
22+
23+
//process
24+
video_application.getProcess = function () {
25+
//value to view to
26+
return(video_application.currentTime / video_application.duration * 100)
27+
.toPrecision(2) + '%';
28+
}
29+
30+
video_application.setProcess = function (percen_num) {
31+
if(percen_num.includes('%')) {
32+
percen_num = percen_num.substr(0, percen_num.indexOf('%'));
33+
}
34+
console.log(percen_num / 100 * video_application.duration);
35+
//view to value
36+
video_application.currentTime = percen_num / 100 * video_application.duration;
37+
}
38+
39+
40+
// initial process
41+
const process = document.querySelector('.progress__filled');
42+
process.style.flexBasis = '0%';
43+
44+
//show
45+
setInterval(function () {
46+
let process_watched = document.querySelector('.progress__filled');
47+
process_watched.style.flexBasis = video_application.getProcess();
48+
console.log('currentTime: ', video_application.getProcess());
49+
}, 1000);
50+
51+
//change
52+
function changeProcess(e) {
53+
const currWatched = ((e.layerX / process_all.clientWidth) * 100)
54+
.toPrecision(2) + '%';
55+
process.style.flexBasis = currWatched;
56+
video_application.setProcess(currWatched);
57+
}
58+
59+
const process_all = document.querySelector('.progress');
60+
process_all.addEventListener('click', changeProcess);
61+
// process_all.addEventListener('mousemove', changeProcess);
62+
63+
64+
//volume
65+
66+
// initial volume
67+
function changeVolume() {
68+
console.log(video_application.volume);
69+
}
70+
const volume_ctrl = document.querySelector('input[name=volume]');
71+
volume_ctrl.value = 0;
72+
volume_ctrl.addEventListener('change', changeVolume);
73+
volume_ctrl.addEventListener('mousemove', changeVolume);

11 Custom Video Player/style.css

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
html {
2+
box-sizing: border-box;
3+
}
4+
5+
*, *:before, *:after {
6+
box-sizing: inherit;
7+
}
8+
9+
body {
10+
margin: 0;
11+
padding: 0;
12+
display:flex;
13+
background:#7A419B;
14+
min-height:100vh;
15+
background: linear-gradient(135deg, #7c1599 0%,#921099 48%,#7e4ae8 100%);
16+
background-size:cover;
17+
align-items: center;
18+
justify-content: center;
19+
}
20+
21+
.player {
22+
max-width:750px;
23+
border:5px solid rgba(0,0,0,0.2);
24+
box-shadow:0 0 20px rgba(0,0,0,0.2);
25+
position: relative;
26+
font-size: 0;
27+
overflow: hidden;
28+
}
29+
30+
/* This css is only applied when fullscreen is active. */
31+
.player:fullscreen {
32+
max-width: none;
33+
width: 100%;
34+
}
35+
36+
.player:-webkit-full-screen {
37+
max-width: none;
38+
width: 100%;
39+
}
40+
41+
.player__video {
42+
width: 100%;
43+
}
44+
45+
.player__button {
46+
background:none;
47+
border:0;
48+
line-height:1;
49+
color:white;
50+
text-align: center;
51+
outline:0;
52+
padding: 0;
53+
cursor:pointer;
54+
max-width:50px;
55+
}
56+
57+
.player__button:focus {
58+
border-color: #ffc600;
59+
}
60+
61+
.player__slider {
62+
width:10px;
63+
height:30px;
64+
}
65+
66+
.player__controls {
67+
display:flex;
68+
position: absolute;
69+
bottom:0;
70+
width: 100%;
71+
transform: translateY(100%) translateY(-5px);
72+
transition:all .3s;
73+
flex-wrap:wrap;
74+
background:rgba(0,0,0,0.1);
75+
}
76+
77+
.player:hover .player__controls {
78+
transform: translateY(0);
79+
}
80+
81+
.player:hover .progress {
82+
height:15px;
83+
}
84+
85+
.player__controls > * {
86+
flex:1;
87+
}
88+
89+
.progress {
90+
flex:10;
91+
position: relative;
92+
display:flex;
93+
flex-basis:100%;
94+
height:5px;
95+
transition:height 0.3s;
96+
background:rgba(0,0,0,0.5);
97+
cursor:ew-resize;
98+
}
99+
100+
.progress__filled {
101+
width:50%;
102+
background:#ffc600;
103+
flex:0;
104+
flex-basis:50%;
105+
}
106+
107+
/* unholy css to style input type="range" */
108+
109+
input[type=range] {
110+
-webkit-appearance: none;
111+
background:transparent;
112+
width: 100%;
113+
margin: 0 5px;
114+
}
115+
input[type=range]:focus {
116+
outline: none;
117+
}
118+
input[type=range]::-webkit-slider-runnable-track {
119+
width: 100%;
120+
height: 8.4px;
121+
cursor: pointer;
122+
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
123+
background: rgba(255,255,255,0.8);
124+
border-radius: 1.3px;
125+
border: 0.2px solid rgba(1, 1, 1, 0);
126+
}
127+
input[type=range]::-webkit-slider-thumb {
128+
height: 15px;
129+
width: 15px;
130+
border-radius: 50px;
131+
background: #ffc600;
132+
cursor: pointer;
133+
-webkit-appearance: none;
134+
margin-top: -3.5px;
135+
box-shadow:0 0 2px rgba(0,0,0,0.2);
136+
}
137+
input[type=range]:focus::-webkit-slider-runnable-track {
138+
background: #bada55;
139+
}
140+
input[type=range]::-moz-range-track {
141+
width: 100%;
142+
height: 8.4px;
143+
cursor: pointer;
144+
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
145+
background: #ffffff;
146+
border-radius: 1.3px;
147+
border: 0.2px solid rgba(1, 1, 1, 0);
148+
}
149+
input[type=range]::-moz-range-thumb {
150+
box-shadow: 0 0 0 rgba(0, 0, 0, 0), 0 0 0 rgba(13, 13, 13, 0);
151+
height: 15px;
152+
width: 15px;
153+
border-radius: 50px;
154+
background: #ffc600;
155+
cursor: pointer;
156+
}

0 commit comments

Comments
 (0)