return time;
};
- // turns a node tree element into a straight up javascript object
- // also converts in and out to start and end
- // also links manifest data with ids
- /*var objectifyAttributes = function ( nodeAttributes ) {
-
- var returnObject = {};
-
- for ( var i = 0, nal = nodeAttributes.length; i < nal; i++ ) {
-
- var key = nodeAttributes.item(i).nodeName,
- data = nodeAttributes.item(i).nodeValue;
-
- // converts in into start
- if (key === "in") {
- returnObject.start = toSeconds( data );
- // converts out into end
- } else if ( key === "out" ){
- returnObject.end = toSeconds( data );
- // this is where ids in the manifest are linked
- } else if ( key === "resourceid" ) {
- Popcorn.extend( returnObject, manifestData[data] );
- // everything else
- } else {
- returnObject[key] = data;
- }
-
- }
-
- return returnObject;
- };*/
-
// creates an object of all atrributes keyed by name
var createTrack = function( name, attributes ) {
var track = {};
track[name] = attributes;
return track;
};
-/*
- // recursive function to process a node, or process the next child node
- var parseNode = function ( node, allAttributes, manifest ) {
- var attributes = {};
- Popcorn.extend( attributes, allAttributes, objectifyAttributes( node.attributes ), { text: node.textContent } );
-
- var childNodes = node.childNodes;
-
- // processes the node
- if ( childNodes.length < 1 || ( childNodes.length === 1 && childNodes[0].nodeType === 3 ) ) {
-
- if ( !manifest ) {
- returnData.data.push( createTrack( node.nodeName, attributes ) );
- } else {
- manifestData[attributes.id] = attributes;
- }
-
- // process the next child node
- } else {
-
- for ( var i = 0; i < childNodes.length; i++ ) {
-
- if ( childNodes[i].nodeType === 1 ) {
- parseNode( childNodes[i], attributes, manifest );
- }
-
- }
- }
- };*/
// this is where things actually start
- // Timings start as second element, but don't assume can jump right to children[1]
- var node = data.xml.documentElement.lastChild;
- var last;
+ // Timings should start at second element, but don't assume can jump right to children[1]
- while (node = node.previousSibling) {
- var sub = {};
- sub.start = toSeconds(node.getAttribute('sampleTime'));
- sub.text = node.getAttribute('text');
-
- // Infer end time, ms accuracy
- sub.end = last ? (last.start - 0.001) : (3.4028235e+38);
-
- returnData.data.push( createTrack("subtitle", sub) );
- last = node;
+ var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
+ var lastStart = 3.4028235e+38;
+ var cmds = [];
+
+ while (node) {
+ if ( node.nodeType === 1 && node.nodeName === "TextSample") {
+ var sub = {};
+ sub.start = toSeconds(node.getAttribute('sampleTime'));
+ sub.text = node.getAttribute('text');
+
+ // Infer end time, ms accuracy
+ sub.end = lastStart;
+
+ cmds.push( createTrack("subtitle", sub) );
+ lastStart = sub.start - 0.001;
+ }
+ node = node.previousSibling;
}
+
+ returnData.data = cmds.reverse();
return returnData;
});