-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (78 loc) · 2.87 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
<!doctype html>
<html>
<head>
<title>webvtt-player</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
webvtt-player (Forked)
<hr>
</header>
<!-- get audio from web -->
<label for="Audio">Audio (from web):</label>
<select id="audio-id">
<option disabled selected value> -- select an option -- </option>
</select>
<br ><br >
<!-- get audio/caption from local -->
<div class="upload">
<span>Audio (from local):</span>
<input type="file" id="video" name="Audio/Video (mp4)" accept=".mp3,.mp4,.mkv,.webm" >
<br>
<span>Caption (from local): </span>
<input type="file" id="caption" name="Caption" accept=".vtt" >
</div>
<br>
<div id="webvtt-player" data-audio="" data-transcript=""></div>
<script id="player-src" type="text/javascript" src="webvtt-player.js"></script>
<script>
var PlayerSrc = document.getElementById('player-src').cloneNode(true);
var select = document.getElementById("audio-id");
function reload_player() {
document.getElementById("player-src").remove();
var script= document.createElement('script');
script.src= PlayerSrc.src;
script.id = "player-src";
document.querySelector("body").appendChild(script);
}
// Audio file dropdown
select.addEventListener("change", function(e) {
var path = select.value;
var player = document.getElementById("webvtt-player")
player.dataset.audio = `data/${path}/audio.mp3`
player.dataset.transcript = `data/${path}/transcript.vtt`
reload_player();
})
// Get Audio paths in data/
fetch('playlist.txt')
.then(function(response) {
return response.text();
})
.then(function(txt) {
var files = txt.trim().split("\n").map( e => e.replace(/\/$/, "") );
files.forEach((e) => {
var opt = document.createElement("option")
opt.value = e;
opt.innerText = e;
select.appendChild(opt)
})
select.dispatchEvent( new Event('change') );
});
// Upload audio/caption from local
const video = document.getElementById("video");
const caption = document.getElementById("caption");
video.addEventListener("change", function() {
const objectURL = window.URL.createObjectURL(this.files[0]);
document.getElementById('webvtt-player').dataset.audio = objectURL;
reload_player();
})
caption.addEventListener("change", function() {
const objectURL = window.URL.createObjectURL(this.files[0]);
document.getElementById('webvtt-player').dataset.transcript = objectURL;
reload_player();
})
</script>
</body>
</html>