forked from cbf02000/um-video-player-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
261 lines (222 loc) · 9.95 KB
/
index.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
<!-- suggestions for future enhancements:
-seek to time demonstration -->
<!doctype html>
<html>
<head>
<title>VideoPlayer</title>
<script src="./VideoPlayer.js"></script>
<script>
var renderObject = {
EDL: [{
url: "video3.mp4",
startTime: 1.0,
endTime: 4.0,
}, {
url: "video2.mp4",
startTime: 26.5,
endTime: 34.0,
}, {
url: "video1.mp4",
startTime: 3,
endTime: 10.5,
}],
};
var player;
// we want these variables to be public because we will access these elements frequently.
// We don't want them to be computed each time they are needed
var progressSlider;
var sliderPosition;
var sliderCompleted;
window.onload = function(){
progressSlider = document.getElementById('progressSlider');
sliderPosition = document.getElementById('sliderPosition');
sliderCompleted = document.getElementById('sliderCompleted')
function loadingErrorHandler(errorMessage) {
console.error(errorMessage);
}
function loadingStartedHandler() {
var loadingContainer = document.getElementById('loadingContainer');
var loadingSymbol = document.getElementById('loadingSymbol');
loadingContainer.style.visibility = 'visible';
loadingSymbol.style.webkitAnimationPlayState = 'running';
}
function loadingStoppedHandler() {
var loadingContainer = document.getElementById('loadingContainer');
var loadingSymbol = document.getElementById('loadingSymbol');
loadingContainer.style.visibility = 'hidden';
loadingSymbol.style.webkitAnimationPlayState = 'paused';
}
function playHandler() {
var playSymbol = document.getElementById('playSymbol');
var pauseSymbol = document.getElementById('pauseSymbol');
playSymbol.style.opacity = 0;
pauseSymbol.style.opacity = 1;
}
function pauseHandler() {
var playSymbol = document.getElementById('playSymbol');
var pauseSymbol = document.getElementById('pauseSymbol');
playSymbol.style.opacity = 1;
pauseSymbol.style.opacity = 0;
}
function timeUpdateHandler() {
var percent = player.currentTime() / player.duration();
sliderPosition.style.left = (percent * (progressSlider.clientWidth - sliderPosition.clientWidth)) + 'px';
if (percent >= 100) {
sliderCompleted.style.width = progressSlider.clientWidth;
}
else {
sliderCompleted.style.width = (percent * (progressSlider.clientWidth - sliderPosition.clientWidth) + (sliderPosition.clientWidth / 2.0)) + 'px';
}
}
player = new VideoPlayer("VideoPlayerContainer", renderObject, {
"classString" : "VideoPlayer",
"transitionTime" : .1,
"loadingErrorHandler" : loadingErrorHandler,
"loadingStartedHandler" : loadingStartedHandler,
"loadingStoppedHandler" : loadingStoppedHandler,
"playHandler" : playHandler,
"pauseHandler" : pauseHandler,
"timeUpdateHandler" : timeUpdateHandler,
});
// create the buttons for seeking to a specific clip
var clipContainer = document.getElementById('clipContainer');
for (var i = 0; i < renderObject.EDL.length; i++)
{
var clipElement = document.createElement('button');
clipElement.setAttribute('class', 'clip');
clipElement.setAttribute('id', 'clip' + i);
clipElement.style.width = (100 / renderObject.EDL.length) + '%';
clipElement.innerText = i + 1;
clipContainer.appendChild(clipElement);
clipElement.addEventListener('click', clipClicked);
}
};
function playPauseClicked() {
player.togglePlayPause();
}
function clipClicked() {
var clipIndex = parseInt(this.id.substring(4));
player.seekToClipIndex(clipIndex);
}
</script>
<style>
/* Video Player */
html {
width: 100%; height: 100%;
}
body {
margin: 0; width: 100%; height: 100%;
}
#VideoPlayerContainer {
width: 100%;
height: -moz-calc(100% - 50px);
height: -webkit-calc(100% - 50px);
height: calc(100% - 50px);
background: black;
}
.VideoPlayer {
width: 100%;
height: -moz-calc(100% - 50px);
height: -webkit-calc(100% - 50px);
height: calc(100% - 50px);
}
#loadingContainer {
position: absolute; top: 0; left: 0; width: 100%;
height: -moz-calc(100% - 50px);
height: -webkit-calc(100% - 50px);
height: calc(100% - 50px);
background: rgba(0, 0, 0, .5);
}
#loadingSymbol {
position: absolute; top: 30%;
width: 100%; height: 40%;
-webkit-animation: spin 3s linear infinite;
/*-webkit-animation-play-state: paused;*/
}
@-webkit-keyframes spin {
100% {-webkit-transform: rotate(360deg);}
}
/* Controls */
/************/
#controlsContainer {
position: absolute; bottom: 0; height: 50px; width: 100%;
}
/* Progress Slider */
#progressSlider {
width: 100%; height: 14px; background: #414141;
}
#sliderCompleted {
position: absolute; top: 0; left: 0;
width: 7px; height: 100%; background: #616161;
}
#sliderPosition {
position: absolute; top: 0; left: 0; width: 14px; height: 14px;
border-radius: 7px; background: rgb(151, 151, 151);
}
/* General Controls */
#generalControls {
position: absolute; bottom: 0; width: 100%; height: 35px;
border-top: 1px solid black; background: #616161;
}
#playPause {
position: absolute; bottom: 0; left: 0;
margin: 0; width: 35px; height: 35px; padding: 0;
border-width: 0; border-right: 1px solid black;
outline: none; cursor: pointer; background: #515151;
}
#playPause:active {
background: #414141;
}
#pauseSymbol {
position: absolute; left: 0; top: 0;
width: 100%; height: 100%; opacity: 0;
}
#clipContainer {
position: absolute; bottom: 0; left: 25%;
width: 50%; height: 100%;
}
.clip {
height: 100%;
float: left;
border-width: 0;
border-left: 1px solid black;
outline: none;
cursor: pointer;
background: #515151;
}
.clip:active {
background: #414141;
}
.clip:last-child {
border-right: 1px solid black;
}
</style>
</head>
<body>
<!-- Placeholder for video player -->
<div id="VideoPlayerContainer"></div>
<div id="loadingContainer">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="loadingSymbol" viewBox="0 0 100 100">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M95.525,52.728c-5.582-1.496-6.847-14.585-2.268-17.228 c1.501-0.87,2.665-2.104,3.434-3.527c-1.191-4.343-5.255-10.6-7.548-13.383c-1.676-0.078-3.39,0.305-4.95,1.206 c-4.995,2.886-15.321-4.833-13.783-10.578c0.481-1.795,0.227-3.972-0.165-5.244c-2.839-1.468-9.562-3.443-14.555-3.932 c-1.076,0.783-2.308,2.676-2.788,4.483c-1.629,6.075-14.52,6.958-17.285,2.17c-0.923-1.6-2.623-3.09-3.798-3.58 c-3.23,0.979-10.249,5.048-13.088,7.397c0.196,1.664,0.234,3.597,1.188,5.247c2.763,4.789-4.72,15.438-10.629,13.855 c-1.944-0.52-3.984-0.372-5.648,0.313C2.271,32.963,0.196,40.97,0,44.2c0.392,0.881,2.729,2.428,4.598,2.928 c8.043,2.156,8.106,13.951,2.279,17.315c-1.646,0.951-3.056,2.271-3.643,3.936c0.979,3.132,4.913,10.018,7.458,12.955 c1.664,0.195,3.597-0.232,5.248-1.187c5.204-3.007,15.612,4.064,13.853,10.631c-0.457,1.709-0.204,3.507,0.089,5.27 c3.916,1.664,11,4.005,14.916,3.907c1.272-1.175,2.057-2.812,2.504-4.483c1.54-5.748,14.253-7.582,17.257-2.378 c0.839,1.455,2.014,2.836,3.384,3.619c4.111-1.175,11.338-5.219,13.788-7.764c0.096-1.859-0.604-3.412-1.474-4.922 c-3.247-5.619,4.338-15.458,10.575-13.786c1.708,0.456,3.568,0.302,5.135-0.089c1.37-3.427,3.642-9.549,4.032-14.639 C98.629,53.947,97.329,53.212,95.525,52.728z M76.521,56.525c-3.807,14.217-18.417,22.651-32.632,18.843 c-14.213-3.81-22.647-18.423-18.839-32.639c3.808-14.216,18.418-22.651,32.631-18.842C71.895,27.696,80.33,42.307,76.521,56.525z"/>
</svg>
</div>
<div id="controlsContainer">
<div id="progressSlider">
<div id="sliderCompleted"></div>
<div id="sliderPosition"></div>
</div>
<div id="generalControls">
<button id="playPause" onclick=playPauseClicked()>
<svg id="playSymbol" viewBox="0 0 100 100">
<path d="M25,20 L80,50 L25,80 Z" fill="#FFFFFF" />
</svg>
<svg id="pauseSymbol" viewBox="0 0 100 100">
<rect x="22" y="20" rx="2" ry="2" width="18" height="60" fill="#FFFFFF" />
<rect x="58" y="20" rx="2" ry="2" width="18" height="60" fill="#FFFFFF" />
</svg>
</button>
<div id="clipContainer"></div>
</div>
</div>
</body>
</html>