-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
276 lines (257 loc) · 7.87 KB
/
index.html
File metadata and controls
276 lines (257 loc) · 7.87 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
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
<!DOCTYPE html>
<html>
<head>
<title>MPlayer</title>
<link href="https://vjs.zencdn.net/7.15.5/video-js.css" rel="stylesheet" />
<link rel="apple-touch-icon" sizes="57x57" href="./apple-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="60x60" href="./apple-icon-60x60.png" />
<link rel="apple-touch-icon" sizes="72x72" href="./apple-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="76x76" href="./apple-icon-76x76.png" />
<link
rel="apple-touch-icon"
sizes="114x114"
href="./apple-icon-114x114.png"
/>
<link
rel="apple-touch-icon"
sizes="120x120"
href="./apple-icon-120x120.png"
/>
<link
rel="apple-touch-icon"
sizes="144x144"
href="./apple-icon-144x144.png"
/>
<link
rel="apple-touch-icon"
sizes="152x152"
href="./apple-icon-152x152.png"
/>
<link
rel="apple-touch-icon"
sizes="180x180"
href="./apple-icon-180x180.png"
/>
<link
rel="icon"
type="image/png"
sizes="192x192"
href="./android-icon-192x192.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="./favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="96x96"
href="./favicon-96x96.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="./favicon-16x16.png"
/>
<link rel="manifest" href="./manifest.json" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png" />
<meta name="theme-color" content="#ffffff" />
<style>
html,
body,
video,
#video-container,
#my-video {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#video-container {
flex-grow: 1;
}
body {
display: flex;
flex-direction: column;
}
body:fullscreen #video-container,
body:fullscreen #my-video {
height: 100%;
}
body:fullscreen > label {
display: none;
}
.vjs-text-track-cue {
pointer-events: auto;
}
.vjs-fullscreen-control,
.vjs-picture-in-picture-control,
.vjs-big-play-button {
display: none !important;
}
/* Hide the default file input element */
input[type="file"] {
display: none;
}
/* Style the label to look like a button */
label.file-input-button {
display: block;
padding: 10px 20px;
background-color: #3498db;
color: #fff;
border: none;
cursor: pointer;
text-align: center;
font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
}
/* Optional: Style the label on hover or focus */
label.file-input-button:hover,
label.file-input-button:focus {
background-color: #2980b9;
}
</style>
</head>
<body>
<label for="file-input" class="file-input-button">
Choose your video and its subtitle (SRT)
<input
type="file"
accept="video/*, .srt, .vtt, .mkv"
id="file-input"
multiple
/>
</label>
<div id="video-container">
<video id="my-video" class="video-js" controls preload="auto"></video>
</div>
<script src="https://vjs.zencdn.net/7.15.5/video.js"></script>
<script src="srt2vtt.js"></script>
<script>
function toggleFullscreen(player) {
if (!document.fullscreenElement) {
document.body.requestFullscreen();
player.is;
} else {
document.exitFullscreen();
}
}
var player = videojs("my-video", {
userActions: {
doubleClick: toggleFullscreen,
hotkeys: function (e) {
if (e.ctrlKey || e.metaKey) {
// Check if Ctrl (or Cmd on macOS) is pressed
if (e.which === 39) {
// Right arrow key
this.currentTime(this.currentTime() + 10); // Skip forward by 10 seconds
} else if (e.which === 37) {
// Left arrow key
this.currentTime(this.currentTime() - 10); // Skip backward by 10 seconds
}
} else {
if (e.which === 37) {
// Left arrow key
this.currentTime(this.currentTime() - 3); // Skip backward by 3 seconds
} else if (e.which === 39) {
// Right arrow key
this.currentTime(this.currentTime() + 3); // Skip forward by 3 seconds
} else if (e.which === 38) {
// Up arrow key
this.volume(this.volume() + 0.1); // Increase volume by 10%
} else if (e.which === 40) {
// Down arrow key
this.volume(this.volume() - 0.1); // Decrease volume by 10%
} else if (e.which === 32) {
// Space key
if (this.paused()) {
this.play(); // Play the video
} else {
this.pause(); // Pause the video
}
}
}
},
},
});
var fileInput = document.getElementById("file-input");
// Add an event listener to the file input element
fileInput.addEventListener("change", function (event) {
var files = event.target.files;
if (files.length <= 2) {
var videoFile = null;
var subtitleFile = null;
player.addRemoteTextTrack({});
var textTracks = player.textTracks();
textTracks.tracks_.forEach(function (track) {
player.removeRemoteTextTrack(track);
});
var trackElement = document.querySelector("track");
if (trackElement) {
trackElement.remove();
}
for (var i = 0; i < files.length; i++) {
if (files[i].type.startsWith("video/")) {
videoFile = files[i];
} else if (files[i].name.toLowerCase().endsWith(".srt")) {
subtitleFile = files[i];
}
}
function preparePlayer(subtitleBlobURL) {
var videoBlobURL = URL.createObjectURL(videoFile);
// Set the video source
player.src({ type: "video/mp4", src: videoBlobURL });
if (subtitleBlobURL) {
// Create a track element for the subtitles
var track = document.createElement("track");
track.kind = "subtitles";
track.label = "Subtitle";
track.srclang = "en";
track.default = true;
track.mode = "showing";
track.src = subtitleBlobURL;
document
.querySelector("body")
.addEventListener("click", function adjustStyles(event) {
if (
event.target.parentNode?.classList.contains(
"vjs-text-track-cue"
)
) {
player.pause();
}
});
// Enable the track for displaying subtitles
player.addRemoteTextTrack({
kind: "subtitles",
label: "Subtitles",
src: subtitleBlobURL,
language: "en",
default: true,
});
}
player.play();
}
if (videoFile) {
if (subtitleFile) {
const webvtt = new WebVTTConverter(subtitleFile);
webvtt
.getURL()
.then((url) => {
preparePlayer(url);
})
.catch((err) => {
console.log(err);
});
} else {
preparePlayer();
}
}
}
});
</script>
</body>
</html>