forked from cgiffard/Captionator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
108 lines (99 loc) · 4.13 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
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Video Closed Captioning Example</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" media="screen" href="css/captions.css"/>
</head>
<body>
<h1>HTML5 Video Closed Captioning Example</h1>
<p><em><strong>Note:</strong> the German and Japanese subtitles are machine translated.</em></p>
<video controls autobuffer id="videoTest" width="1024" height="464">
<source src="video/arduino.m4v" type="video/mp4" />
<source src="video/arduino.webm" type="video/webm" />
<source src="video/arduino.ogv" type="video/ogg" />
<track kind="captions" src="video/arduino-en.srt" type="text/srt" srclang="en" label="English Subtitles" default />
<track kind="captions" src="video/arduino-de.srt" type="text/srt" srclang="de" label="German Subtitles" />
<track kind="captions" src="video/arduino-ja.srt" type="text/srt" srclang="ja" label="Japanese Subtitles" />
</video>
<h2>Media Controls</h2>
<div id="controls"></div>
<h2>Transcript</h2>
<div id="transcript"></div>
<script type="text/javascript" src="js/captionator.js"></script>
<!--
The following sets up captionator and shows how you can use the
TextTrack API to pull out all the cues of a track into a transcript.
-->
<script type="text/javascript">
window.addEventListener("load",function(eventData) {
// initialise Captionator so functionality is available
captionator.captionify();
// creates a transcript from a track's text data
generateTranscript = function(track, transcriptDestination) {
var captionID, captionData;
if (typeof(transcriptDestination) === "string") {
transcriptDestination = document.querySelectorAll(transcriptDestination)[0];
}
if (typeof(transcriptDestination) === "object") {
if (track.readyState === captionator.TextTrack.LOADED) {
transcriptDestination.innerHTML = "";
track.cues.forEach(function(cue) {
transcriptDestination.innerHTML += "<p class='transcriptLine'>" + cue.getCueAsSource() + "</p>";
});
} else {
if (track.readyState === captionator.TextTrack.LOADING) {
track.onload = function() {
generateTranscript(track, transcriptDestination);
}
} else { // ERROR or NONE
track.loadTrack(track.src,function() {
generateTranscript(track, transcriptDestination);
});
}
}
} else {
return false;
}
};
// create transcript for any default loaded tracks
document.getElementById("videoTest").tracks.forEach(function(track) {
// enable track & update transcript
if (track.mode === captionator.TextTrack.SHOWING) {
generateTranscript(track, "#transcript");
}
});
},false);
</script>
<!--
The following script demonstrates how you can use the API to enable and disable
caption tracks. This functionality should eventually be part of the @controls of the video.
-->
<script type="text/javascript">
// build the caption track switcher and callback for switching tracks
window.addEventListener("load",function(eventData) {
var subtitleSelector = document.createElement("select");
document.getElementById("controls").appendChild(subtitleSelector);
subtitleSelector.addEventListener("change",function(eventData) {
trackToEnable = parseInt(eventData.target.value,10);
document.getElementById("videoTest").tracks.forEach(function(track,index) {
if (index === trackToEnable) {
// enable track & update transcript
track.mode = captionator.TextTrack.SHOWING;
generateTranscript(track, "#transcript");
} else if (track.mode != captionator.TextTrack.OFF) {
// hide showing tracks
track.mode = captionator.TextTrack.HIDDEN;
}
});
},false);
document.getElementById("videoTest").tracks.forEach(function(track,index) {
var subtitleOption = document.createElement("option");
subtitleOption.innerHTML = track.label + " (" + track.language + ")";
subtitleOption.setAttribute("value",index);
subtitleSelector.appendChild(subtitleOption);
});
},false);
</script>
</body>
</html>