// The video manager manages a single video element, and all it's commands.
var VideoManager = this.VideoManager = function(videoElement) {
- this.commandObjects = {};
+ this.commandObjects = {};
+ this.manifestObjects = {};
this.videoElement = videoElement;
videoElement.videoManager = this;
VideoManager.addInstance(this);
VideoManager.prototype.removeCommand = function(command) {
delete this.commandObjects[command.id];
};
+ VideoManager.prototype.addManifestObject = function(manifestAttributes) {
+ var manifest = {};
+ var manifestId = "";
+ for (var i = 0, pl = manifestAttributes.length; i < pl; i++) {
+ for (var j = 0, nl = manifestAttributes[i].length; j < nl; j++) {
+ var key = manifestAttributes[i].item(j).nodeName,
+ data = manifestAttributes[i].item(j).nodeValue;
+ if (key === "id") {
+ manifestId = data;
+ } else {
+ manifest[key] = data;
+ }
+ }
+ }
+ this.manifestObjects[manifestId] = manifest;
+ };
+ VideoManager.prototype.removeManifestObject = function(itemId) {
+ delete this.manifestObjects[itemId];
+ };
// Update is called on the video every time it's time changes.
VideoManager.update = function(vid, manager) {
var t = vid.currentTime;
////////////////////////////////////////////////////////////////////////////
// Command objects
- ///////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
// Base class for all commands, SubtitleCommand, MapCommand, etc.
- var VideoCommand = function(name, params, text) {
+ var VideoCommand = function(name, params, text, videoManager) {
this.params = {};
this.text = text;
+ this.videoManager = videoManager;
this.running = false;
this.loaded = false;
this.onIn = function() {};
}
}
}
+ // Checkes for a resourceid and gets all the attributes from that resource
+ if (this.params.resourceid) {
+ for (var attributeName in this.videoManager.manifestObjects[this.params.resourceid]) {
+ if (this.videoManager.manifestObjects[this.params.resourceid].hasOwnProperty(attributeName)) {
+ this.params[attributeName] = this.videoManager.manifestObjects[this.params.resourceid][attributeName];
+ }
+ }
+ }
};
VideoCommand.count = 0;
- // Child commands. Uses onIn() and onOut() to do time based operations
- var SubtitleCommand = function(name, params, text) {
- VideoCommand.call(this, name, params, text);
+ ////////////////////////////////////////////////////////////////////////////
+ // Subtitle Command
+ ////////////////////////////////////////////////////////////////////////////
+
+ var SubtitleCommand = function(name, params, text, videoManager) {
+ VideoCommand.call(this, name, params, text, videoManager);
this.onIn = function() {
document.getElementById("sub").innerHTML = this.text;
};
};
};
- var TagCommand = function(name, params, text) {
- VideoCommand.call(this, name, params, text);
+ ////////////////////////////////////////////////////////////////////////////
+ // TagThisPerson Command
+ ////////////////////////////////////////////////////////////////////////////
+
+ var TagCommand = function(name, params, text, videoManager) {
+ VideoCommand.call(this, name, params, text, videoManager);
this.onIn = function() {
TagCommand.people.contains[this.text] = this.text;
document.getElementById("inthisvideo").innerHTML = TagCommand.people.toString();
}
};
- var MapCommand = function(name, params, text) {
- VideoCommand.call(this, name, params, text);
+ ////////////////////////////////////////////////////////////////////////////
+ // Map Command
+ ////////////////////////////////////////////////////////////////////////////
+
+ var MapCommand = function(name, params, text, videoManager) {
+ VideoCommand.call(this, name, params, text, videoManager);
this.params.zoom = parseInt(this.params.zoom, 10);
// load the map
// http://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions <-- Map API
};
};
- var TwitterCommand = function(name, params, text) {}; // http://twitter.com/celinecelines
+ ////////////////////////////////////////////////////////////////////////////
+ // Twitter Command
+ ////////////////////////////////////////////////////////////////////////////
+
+ var TwitterCommand = function(name, params, text, videoManager) {}; // http://twitter.com/celinecelines
// Wrapper for accessing commands by name
// commands[name].create() returns a new command of type name
// I liked it more than a switch, though
var commands = {
subtitle: {
- create: function(name, params, text) {
- return new SubtitleCommand(name, params, text);
+ create: function(name, params, text, videoManager) {
+ return new SubtitleCommand(name, params, text, videoManager);
}
},
tagThisVideo: {
- create: function(name, params, text) {
- return new TagCommand(name, params, text);
+ create: function(name, params, text, videoManager) {
+ return new TagCommand(name, params, text, videoManager);
}
},
location: {
- create: function(name, params, text) {
- return new MapCommand(name, params, text);
+ create: function(name, params, text, videoManager) {
+ return new MapCommand(name, params, text, videoManager);
}
}
};
+ ////////////////////////////////////////////////////////////////////////////
+ // XML Parser
+ ////////////////////////////////////////////////////////////////////////////
+
// Parses xml into command objects and adds them to the video manager
var parse = function(xmlDoc, videoManager) {
- var parseNode = function(node, attributes) {
+
+ var parseNode = function(node, attributes, manifest) {
var allAttributes = attributes.slice(0);
allAttributes.push(node.attributes);
var childNodes = node.childNodes;
if (childNodes.length < 1 || (childNodes.length === 1 && childNodes[0].nodeType === 3)) {
- videoManager.addCommand(commands[node.nodeName].create(node.nodeName, allAttributes, node.textContent));
+ if (!manifest) {
+ videoManager.addCommand(commands[node.nodeName].create(node.nodeName, allAttributes, node.textContent, videoManager));
+ } else {
+ videoManager.addManifestObject(allAttributes);
+ }
} else {
for (var i = 0; i < childNodes.length; i++) {
if (childNodes[i].nodeType === 1) {
- parseNode(childNodes[i], allAttributes);
+ parseNode(childNodes[i], allAttributes, manifest);
}
}
}
var x = xmlDoc[j].documentElement.childNodes;
for (var i = 0, xl = x.length; i < xl; i++) {
if (x[i].nodeType === 1) {
- parseNode(x[i], []);
+ if (x[i].nodeName === "manifest") {
+ parseNode(x[i], [], true);
+ } else {
+ parseNode(x[i], [], false);
+ }
}
}
}
<popcorn>
- <subtitles>
- <subtitle in="00:05:00" out="00:07:00">Hello! My name is Celine Celine</subtitle>
- <subtitle in="00:07:00" out="00:09:00">And I help the Internet be easier</subtitle>
- <subtitle in="00:09:00" out="00:12:00">by making things easier</subtitle>
- <subtitle in="00:15:00" out="00:17:00">My name is Mona Kasra</subtitle>
- <subtitle in="00:17:00" out="00:19:00">and I'm building a better internet</subtitle>
- </subtitles>
- <inThisVideo>
- <tagThisVideo in="00:03:00" out="00:14:00">Celine Celine</tagThisVideo>
- <tagThisVideo in="00:13:00" out="00:16:00">Bryan</tagThisVideo>
- <tagThisVideo in="00:15:00" out="00:19:00">Mona Kasra</tagThisVideo>
- <tagThisVideo in="00:19:00" out="00:21:00">Caleb</tagThisVideo>
- <tagThisVideo in="00:21:00" out="00:31:00">Dave</tagThisVideo>
- <tagThisVideo in="00:21:00" out="00:33:00">Noah</tagThisVideo>
- <tagThisVideo in="00:39:00" out="00:41:00">Celine Celine</tagThisVideo>
- </inThisVideo>
- <map>
- <location id="map1" in="00:01:00" out="00:30:00" lat="45.505" long="-73.335" target="map" zoom="8"/>
- <location id="map2" in="00:30:00" out="01:00:00" lat="43.771" long="-79.5" target="map" zoom="16"/>
- <location id="map3" in="01:00:00" out="01:30:00" lat="41.771" long="-76.5" target="map" zoom="16"/>
- </map>
+ <manifest>
+ <location id="number1" lat="45.505" long="-73.335" target="map" zoom="8"/>
+ </manifest>
+ <timeline>
+ <subtitles>
+ <subtitle in="00:05:00" out="00:07:00">Hello! My name is Celine Celine</subtitle>
+ <subtitle in="00:07:00" out="00:09:00">And I help the Internet be easier</subtitle>
+ <subtitle in="00:09:00" out="00:12:00">by making things easier</subtitle>
+ <subtitle in="00:15:00" out="00:17:00">My name is Mona Kasra</subtitle>
+ <subtitle in="00:17:00" out="00:19:00">and I'm building a better internet</subtitle>
+ </subtitles>
+ <inThisVideo>
+ <tagThisVideo in="00:03:00" out="00:14:00">Celine Celine</tagThisVideo>
+ <tagThisVideo in="00:13:00" out="00:16:00">Bryan</tagThisVideo>
+ <tagThisVideo in="00:15:00" out="00:19:00">Mona Kasra</tagThisVideo>
+ <tagThisVideo in="00:19:00" out="00:21:00">Caleb</tagThisVideo>
+ <tagThisVideo in="00:21:00" out="00:31:00">Dave</tagThisVideo>
+ <tagThisVideo in="00:21:00" out="00:33:00">Noah</tagThisVideo>
+ <tagThisVideo in="00:39:00" out="00:41:00">Celine Celine</tagThisVideo>
+ </inThisVideo>
+ <map>
+ <location in="00:01:00" out="00:30:00" resourceid="number1"/>
+ <location in="00:30:00" out="01:00:00" lat="43.771" long="-79.5" target="map" zoom="16"/>
+ <location in="01:00:00" out="01:30:00" lat="41.771" long="-76.5" target="map" zoom="16"/>
+ </map>
+ </timeline>
</popcorn>