are "messed up".
*
* 2/9/15
*
* Format of the division:
*
*
* cueId~startTime~endTime~cueText (repeat for each cue)
*
*
* Example
* 4~7.100~11.000~Developers all around the world who are
* using our tools to create great new things~
*
* Notes: "4" is the id for this cue. Nothing special needs to be done
* for standard HTML tags like and . On the other hand, for
* WebVTT tags that are not HTML tags, the "<" and ">" for "v ...> must
* be replaced by "`l" and "`g".
*
* Reference for adding a track and cues:
* http://msdn.microsoft.com/en-us/library/ie/dn265043%28v=vs.85%29.aspx
*
*/
/**
* Read cues from divisions in the .html file
* Then make corrections and split it into individual items. It then
* calls a routine that adds the track to the video.
*/
void readCuesFromHTML(String label, String languageCode, String divId) {
String startTime, endTime, message;
String aStr;
String[] result;
int i;
msgStr += NEW_LINE + "***Read cues from HTML file";
// read from the .html file, make changes, and split it into items
aStr = document.getElementById(divId).innerHTML;
// VTT tags (e.g. ) not in HTML5, are messed up by the above read.
// So use "`l" by "<" and "`g" by ">".
aStr = replaceAll(aStr, "`l", "<");
aStr = replaceAll(aStr, "`g", ">");
result = aStr.split("~");
showInfo("readCuesFromHTML");
// create the track using the cues in result
createNewTrack(label, languageCode, result);
// do things required by the sketch
KISVidTBookKeeping(video.textTracks.length - 1, "HTML file");
} // readCuesFromHTML
/**
* creates a new track and its cues using the info provided in "result".
*/
void createNewTrack(String label, String languageCode, String[] result) {
double id, startTime, endTime, message;
Track newTextTrack;
int i;
newTextTrack = video.addTextTrack("subtitles", label, languageCode);
newTextTrack.mode = "hidden"; // temporarily hide the track
showInfo("createNewTrack " + result.length + " ");
// each cue requires 4 pieces of info
try {
for (i = 0; i < result.length; i += 4) {
cueNo = i/4;
startTime = result[i+1];
endTime = result[i+2];
message = result[i+3];
newTextTrack.addCue(newCue(startTime, endTime, message));
try { // the id must be added independently
newTextTrack.cues[cueNo].id = result[i];
} catch (Exception e) {
// ignore
}
}
} catch (Exception e) {
alert ("Error: while creating a track and adding ques. " + e);
}
cueStr = "Finished adding English track for video 1" + trackLangs[videoNo][languageNo] + " cues";
showInfo("Completed the English track for Kitten video");
} // createNewTrack