--- a/web/res/metadataplayer/LdtPlayer-core.js Thu Jun 14 16:05:27 2012 +0200
+++ b/web/res/metadataplayer/LdtPlayer-core.js Wed Jun 20 18:46:56 2012 +0200
@@ -29,7 +29,7 @@
/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */
-IriSP.Metadataplayer = function(config, video_metadata) {
+IriSP.Metadataplayer = function(config) {
IriSP.log("IriSP.Metadataplayer constructor");
for (var key in IriSP.guiDefaults) {
if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) {
@@ -38,14 +38,37 @@
}
var _container = document.getElementById(config.gui.container);
_container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>';
- this.video_metadata = video_metadata;
this.sourceManager = new IriSP.Model.Directory();
this.config = config;
+ this.callbackQueue = [];
+ this.isLoaded = false;
this.loadLibs();
}
IriSP.Metadataplayer.prototype.toString = function() {
- return 'A Metadataplayer in DIV #' + this.config.gui.container;
+ return 'Metadataplayer in #' + this.config.gui.container;
+}
+
+IriSP.Metadataplayer.prototype.deferCallback = function(_callback) {
+ var _this = this;
+ IriSP._.defer(function() {
+ _callback.call(_this);
+ });
+}
+
+IriSP.Metadataplayer.prototype.handleCallbacks = function() {
+ this.isLoaded = true;
+ while (this.callbackQueue.length) {
+ this.deferCallback(this.callbackQueue.splice(0,1)[0]);
+ }
+}
+
+IriSP.Metadataplayer.prototype.onLoad = function(_callback) {
+ if (this.isLoaded) {
+ this.deferCallback(_callback);
+ } else {
+ this.callbackQueue.push(_callback);
+ }
}
IriSP.Metadataplayer.prototype.loadLibs = function() {
@@ -54,8 +77,13 @@
.script(IriSP.getLib("underscore"))
.script(IriSP.getLib("Mustache"))
.script(IriSP.getLib("jQuery"))
- .script(IriSP.getLib("swfObject"))
- .wait()
+ .script(IriSP.getLib("swfObject"));
+
+ if (typeof JSON == "undefined") {
+ $L.script(IriSP.getLib("json"));
+ }
+
+ $L.wait()
.script(IriSP.getLib("jQueryUI"));
if (this.config.player.type === "jwplayer" || this.config.player.type === "auto") {
@@ -92,7 +120,7 @@
IriSP.loadCss(IriSP.getLib("cssjQueryUI"));
IriSP.loadCss(this.config.gui.css);
- this.videoData = this.loadMetadata(this.video_metadata);
+ this.videoData = this.loadMetadata(this.config.player.metadata);
this.$ = IriSP.jQuery('#' + this.config.gui.container);
this.$.css({
"width": this.config.gui.width,
@@ -143,6 +171,7 @@
});
};
this.$.find('.Ldt-Loader').detach();
+ this.handleCallbacks();
}
IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
@@ -173,7 +202,7 @@
IriSP.Metadataplayer.prototype.configurePopcorn = function() {
IriSP.log("IriSP.Metadataplayer.prototype.configurePopcorn");
var pop,
- ret = this.layoutDivs("video"),
+ ret = this.layoutDivs("video",this.config.player.height || undefined),
containerDiv = ret[0],
spacerDiv = ret[1],
_this = this,
@@ -216,6 +245,25 @@
pop = Popcorn("#" + _tmpId);
break;
+ case "html5-audio":
+ var _tmpId = Popcorn.guid("audio"),
+ _videoEl = IriSP.jQuery('<audio>');
+
+ _videoEl.attr({
+ "src" : this.config.player.video,
+ "id" : _tmpId
+ })
+
+ if(this.config.player.hasOwnProperty("width")) {
+ _videoEl.attr("width", this.config.player.width);
+ }
+ if(this.config.player.hasOwnProperty("height")) {
+ _videoEl.attr("height", this.config.player.height);
+ }
+ IriSP.jQuery("#" + containerDiv).append(_videoEl);
+ pop = Popcorn("#" + _tmpId);
+ break;
+
case "jwplayer":
var opts = IriSP.jQuery.extend({}, this.config.player);
delete opts.container;
@@ -224,7 +272,7 @@
delete opts.video;
if(!opts.hasOwnProperty("flashplayer")) {
- opts.flashplayer = IriSP.jwplayer_swf_path;
+ opts.flashplayer = IriSP.getLib("jwPlayerSWF");
}
if(!opts.hasOwnProperty("controlbar.position")) {
@@ -264,6 +312,10 @@
pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player);
break;
+ case "mashup-html":
+ pop = new IriSP.PopcornReplacement.htmlMashup("#" + containerDiv, this.config.player, this.videoData);
+ break;
+
default:
pop = undefined;
};
@@ -275,7 +327,7 @@
@param widgetName the name of the widget.
@return an array of the form [createdivId, spacerdivId].
*/
-IriSP.Metadataplayer.prototype.layoutDivs = function(_name) {
+IriSP.Metadataplayer.prototype.layoutDivs = function(_name, _height) {
if (typeof(_name) === "undefined") {
_name = "";
}
@@ -296,6 +348,9 @@
position: "relative",
clear: "both"
});
+ if (typeof _height !== "undefined") {
+ divHtml.css("height", _height);
+ }
this.$.append(divHtml);
this.$.append(spacerHtml);
@@ -373,7 +428,7 @@
a segment (similar to the popcorn.code plugin). */
this._options = options;
-
+
};
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
@@ -383,6 +438,8 @@
this.msgPump[msg].push(callback);
};
+IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen;
+
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
if (!this.msgPump.hasOwnProperty(msg))
return;
@@ -395,6 +452,8 @@
};
+IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger;
+
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
@@ -438,16 +497,13 @@
IriSP.PopcornReplacement.player.prototype.play = function() {
this.media.paused = false;
this.trigger("play");
- //IriSP.PopcornReplacement.trigger("playing");
this.playerFns.play();
};
IriSP.PopcornReplacement.player.prototype.pause = function() {
-// if ( !this.media.paused ) {
this.media.paused = true;
this.trigger( "pause" );
this.playerFns.pause();
-// }
};
IriSP.PopcornReplacement.player.prototype.muted = function(val) {
@@ -487,7 +543,13 @@
return _vol;
};
-IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted;
+IriSP.PopcornReplacement.player.prototype.mute = function() {
+ this.muted(true);
+}
+
+IriSP.PopcornReplacement.player.prototype.unmute = function() {
+ this.muted(false);
+}
IriSP.PopcornReplacement.player.prototype.code = function(options) {
this.__codes.push(options);
@@ -561,15 +623,35 @@
IriSP.PopcornReplacement.player.prototype.roundTime = function() {
var currentTime = this.currentTime();
return Math.round(currentTime);
-};/* model.js is where data is stored in a standard form, whatever the serializer */
+};/* TODO: Separate Project-specific data from Source */
+
+/* model.js is where data is stored in a standard form, whatever the serializer */
IriSP.Model = {
_SOURCE_STATUS_EMPTY : 0,
_SOURCE_STATUS_WAITING : 1,
_SOURCE_STATUS_READY : 2,
_ID_AUTO_INCREMENT : 0,
+ _ID_BASE : (function(_d) {
+ function pad(n){return n<10 ? '0'+n : n}
+ function fillrand(n) {
+ var _res = ''
+ for (var i=0; i<n; i++) {
+ _res += Math.floor(16*Math.random()).toString(16);
+ }
+ return _res;
+ }
+ return _d.getUTCFullYear() + '-'
+ + pad(_d.getUTCMonth()+1) + '-'
+ + pad(_d.getUTCDate()) + '-'
+ + fillrand(16);
+ })(new Date()),
getUID : function() {
- return "autoid-" + (++this._ID_AUTO_INCREMENT);
+ var _n = (++this._ID_AUTO_INCREMENT).toString();
+ while (_n.length < 4) {
+ _n = '0' + _n
+ }
+ return "autoid-" + this._ID_BASE + '-' + _n;
},
regexpFromTextOrArray : function(_textOrArray) {
function escapeText(_text) {
@@ -610,7 +692,7 @@
_res.setTime(Number(time));
return _res;
},
- dateToIso : function(d) {
+ dateToIso : function(d) {
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
@@ -773,26 +855,33 @@
});
}
-IriSP.Model.List.prototype.removeId = function(_id) {
- var _index = (IriSP._(this.idIndex).indexOf(_id));
+IriSP.Model.List.prototype.removeId = function(_id, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _index = (IriSP._(this.idIndex).indexOf(_id));
if (_index !== -1) {
this.splice(_index,1);
}
+ if (_deleteFromDirectory) {
+ delete this.directory.elements[_id];
+ }
}
-IriSP.Model.List.prototype.removeElement = function(_el) {
+IriSP.Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false;
this.removeId(_el.id);
}
-IriSP.Model.List.prototype.removeIds = function(_list) {
- var _this = this;
+IriSP.Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _this = this;
IriSP._(_list).forEach(function(_id) {
_this.removeId(_id);
});
}
-IriSP.Model.List.prototype.removeElements = function(_list) {
- var _this = this;
+IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) {
+ var _deleteFromDirectory = _deleteFromDirectory || false,
+ _this = this;
IriSP._(_list).forEach(function(_el) {
_this.removeElement(_el);
});
@@ -832,11 +921,11 @@
}
IriSP.Model.Time.prototype.getSeconds = function() {
- return Math.floor(this.milliseconds / 1000);
+ return this.milliseconds / 1000;
}
IriSP.Model.Time.prototype.getHMS = function() {
- var _totalSeconds = Math.abs(this.getSeconds());
+ var _totalSeconds = Math.abs(Math.floor(this.getSeconds()));
return {
hours : Math.floor(_totalSeconds / 3600),
minutes : (Math.floor(_totalSeconds / 60) % 60),
@@ -874,14 +963,11 @@
IriSP.Model.Reference = function(_source, _idRef) {
this.source = _source;
+ this.id = _idRef;
if (typeof _idRef === "object") {
this.isList = true;
- this.id = IriSP._(_idRef).map(function(_id) {
- return _source.getNamespaced(_id).fullname;
- });
} else {
this.isList = false;
- this.id = _source.getNamespaced(_idRef).fullname;
}
this.refresh();
}
@@ -922,8 +1008,7 @@
_id = IriSP.Model.getUID();
}
this.source = _source;
- this.namespacedId = _source.getNamespaced(_id)
- this.id = this.namespacedId.fullname;
+ this.id = _id;
this.title = "";
this.description = "";
this.source.directory.addElement(this);
@@ -1063,7 +1148,7 @@
/* */
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) {
- IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source);
+ IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source);
this.elementType = 'mashedAnnotation';
this.annotation = _annotation;
this.begin = new IriSP.Model.Time(_mashup.duration);
@@ -1167,54 +1252,10 @@
})
this.callbackQueue = [];
this.contents = {};
- if (typeof this.namespace === "undefined") {
- this.namespace = "metadataplayer";
- } else {
- if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") {
- var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g),
- _url = _matches[0];
- if (_matches.length > 1) {
- _matches = IriSP._(_matches.slice(1)).reject(function(_txt) {
- return /\?$/.test(_txt);
- });
- }
- if (_matches.length > 0) {
- _url += '?' + _matches.join('&');
- }
- this.namespaceUrl = _url;
- }
- }
- if (typeof this.namespaceUrl === "undefined") {
- this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/";
- }
- this.directory.addNamespace(this.namespace, this.namespaceUrl);
this.get();
}
}
-IriSP.Model.Source.prototype.getNamespaced = function(_id) {
- var _tab = _id.split(':');
- if (_tab.length > 1) {
- return {
- namespace : _tab[0],
- name : _tab[1],
- fullname : _id
- }
- } else {
- return {
- namespace : this.namespace,
- name : _id,
- fullname : this.namespace + ':' + _id
- }
- }
-}
-
-IriSP.Model.Source.prototype.unNamespace = function(_id) {
- if (typeof _id !== "undefined") {
- return _id.replace(this.namespace + ':', '');
- }
-}
-
IriSP.Model.Source.prototype.addList = function(_listId, _contents) {
if (typeof this.contents[_listId] === "undefined") {
this.contents[_listId] = new IriSP.Model.List(this.directory);
@@ -1241,7 +1282,7 @@
}
IriSP.Model.Source.prototype.getElement = function(_elId) {
- return this.directory.getElement(this.getNamespaced(_elId).fullname);
+ return this.directory.getElement(_elId);
}
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
@@ -1256,21 +1297,6 @@
}
}
-IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) {
- var _this = this,
- _nsls = [],
- _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf);
- this.forEach(function(_list) {
- IriSP._(_list).forEach(function(_el) {
- var _ns = _el.id.replace(/:.*$/,'');
- if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) {
- _nsls.push(_ns);
- }
- })
- });
- return _nsls;
-}
-
IriSP.Model.Source.prototype.get = function() {
this.status = IriSP.Model._SOURCE_STATUS_WAITING;
this.handleCallbacks();
@@ -1348,6 +1374,13 @@
}
}
+IriSP.Model.Source.prototype.merge = function(_source) {
+ var _this = this;
+ _source.forEach(function(_value, _key) {
+ _this.getList(_key).addElements(_value);
+ });
+}
+
/* */
IriSP.Model.RemoteSource = function(_config) {
@@ -1370,14 +1403,12 @@
IriSP.Model.Directory = function() {
this.remoteSources = {};
this.elements = {};
- this.namespaces = {};
-}
-
-IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) {
- this.namespaces[_namespace] = _url;
}
IriSP.Model.Directory.prototype.remoteSource = function(_properties) {
+ if (typeof _properties !== "object" || typeof _properties.url === "undefined") {
+ throw "Error : IriSP.Model.Directory.remoteSource(configuration): configuration.url is undefined";
+ }
var _config = IriSP._({ directory: this }).extend(_properties);
if (typeof this.remoteSources[_properties.url] === "undefined") {
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config);
@@ -1420,7 +1451,9 @@
popcorn : "popcorn-complete.min.js",
jwplayer : "jwplayer.js",
raphael : "raphael-min.js",
- tracemanager : "tracemanager.js"
+ tracemanager : "tracemanager.js",
+ jwPlayerSWF : "player.swf",
+ json : "json2.js"
},
locations : {
// use to define locations outside defautl_dir
@@ -1526,7 +1559,15 @@
}
}
- this.l10n = (typeof this.messages[IriSP.language] !== "undefined" ? this.messages[IriSP.language] : this.messages["en"]);
+ this.l10n = (
+ typeof this.messages[IriSP.language] !== "undefined"
+ ? this.messages[IriSP.language]
+ : (
+ IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined"
+ ? this.messages[IriSP.language.substr(0,2)]
+ : this.messages["en"]
+ )
+ );
};
@@ -1570,14 +1611,7 @@
*/
IriSP.Widgets.Widget.prototype.draw = function() {
/* implemented by "sub-classes" */
-};
-/**
- * Optional method if you want your widget to support redraws.
- */
-IriSP.Widgets.Widget.prototype.redraw = function() {
- /* implemented by "sub-classes" */
-};
-/* To wrap a player the develop should create a new class derived from
+};/* To wrap a player the develop should create a new class derived from
the IriSP.PopcornReplacement.player and defining the correct functions */
/** allocine player wrapper */
@@ -1851,29 +1885,174 @@
/** jwplayer player wrapper */
IriSP.PopcornReplacement.jwplayer = function(container, options) {
- /* appel du parent pour initialiser les structures communes à tous les players */
- IriSP.PopcornReplacement.player.call(this, container, options);
+ /* appel du parent pour initialiser les structures communes à tous les players */
+ IriSP.PopcornReplacement.player.call(this, container, options);
- this.media.duration = options.duration; /* optional */
+ this.media.duration = options.duration; /* optional */
+
+ var _player = jwplayer(this.container);
/* Définition des fonctions de l'API - */
- this.playerFns = {
- play: function() { return jwplayer(this.container).play(); },
- pause: function() { return jwplayer(this.container).pause(); },
- getPosition: function() { return jwplayer(this.container).getPosition(); },
- seek: function(pos) { return jwplayer(this.container).seek(pos); },
- getMute: function() { return jwplayer(this.container).getMute() },
- setMute: function(p) { return jwplayer(this.container).setMute(p); },
- getVolume: function() { return jwplayer(this.container).getVolume() / 100; },
- setVolume: function(p) { return jwplayer(this.container).setVolume(Math.floor(100*p)); }
- }
+ this.playerFns = {
+ play: function() { return _player.play(); },
+ pause: function() { return _player.pause(); },
+ getPosition: function() { return _player.getPosition(); },
+ seek: function(pos) { return _player.seek(pos); },
+ getMute: function() { return _player.getMute() },
+ setMute: function(p) { return _player.setMute(p); },
+ getVolume: function() { return _player.getVolume() / 100; },
+ setVolume: function(p) { return _player.setVolume(Math.floor(100*p)); }
+ }
- options.events = this.callbacks;
+ options.events = this.callbacks;
- jwplayer(this.container).setup(options);
+ _player.setup(options);
};
IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
+/* To wrap a player the develop should create a new class derived from
+ the IriSP.PopcornReplacement.player and defining the correct functions */
+
+/** jwplayer player wrapper */
+IriSP.PopcornReplacement.htmlMashup = function(container, options, metadata) {
+ /* appel du parent pour initialiser les structures communes à tous les players */
+ IriSP.PopcornReplacement.player.call(this, container, options);
+
+ this.mashup = metadata.currentMedia;
+ this.$ = IriSP.jQuery(container);
+
+ var _w = this.$.width(),
+ _h = this.$.height(),
+ _this = this;
+
+ IriSP._(metadata.currentMedia.medias).each(function(_media) {
+ var _tmpId = Popcorn.guid("video"),
+ _videoEl = IriSP.jQuery('<video>');
+
+ _videoEl
+ .attr({
+ src : _media.video,
+ id : _tmpId,
+ width : _w,
+ height : _h
+ })
+ .css({
+ position: "absolute",
+ top: 0,
+ left: 0
+ });
+
+ _this.$.append(_videoEl);
+ _media.videoEl = _videoEl;
+ _media.popcorn = Popcorn("#" + _tmpId);
+ _media.popcorn.on("timeupdate", function() {
+ if (!_this.media.paused && _media === _this.currentMedia) {
+ var _time = _media.popcorn.currentTime();
+ // var _status = "Timeupdate from " + _media.id + " at time " + _time;
+ if ( _time < _this.segmentEnd ) {
+ if ( _time >= _this.segmentBegin ) {
+ _this.timecode = _time - _this.timedelta;
+ // _status += " within segment";
+ } else {
+ _this.timecode = _this.segmentBegin - _this.timedelta;
+ _media.popcorn.currentTime(_this.segmentBegin);
+ // _status += " before segment begin";
+ }
+ } else {
+ _this.timecode = _this.segmentEnd - _this.timedelta;
+ _media.popcorn.pause();
+ _this.changeCurrentAnnotation();
+ // _status += " after segment end";
+ }
+ /* _status += ", translated to " + _this.timecode;
+ console.log(_status); */
+ _this.trigger("timeupdate");
+ }
+ });
+ });
+
+ this.timecode = 0;
+
+ /* Définition des fonctions de l'API */
+ this.playerFns = {
+ play: function() {
+ _this.changeCurrentAnnotation();
+ },
+ pause: function() {
+ _this.currentMedia.popcorn.pause();
+ },
+ getPosition: function() {
+ return _this.timecode;
+ },
+ seek: function(pos) {
+ _this.timecode = pos;
+ _this.changeCurrentAnnotation();
+ },
+ getMute: function() {
+ return
+ typeof _this.currentMedia !== "undefined"
+ ? _this.currentMedia.popcorn.muted()
+ : false;
+ },
+ setMute: function(p) {
+ var _mute = !!p;
+ for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
+ _this.mashup.medias[_i].popcorn.muted(_mute);
+ }
+ },
+ getVolume: function() {
+ return
+ typeof _this.currentMedia !== "undefined"
+ ? _this.currentMedia.popcorn.volume()
+ : .5;
+ },
+ setVolume: function(_vol) {
+ for (var _i = 0; _i < _this.mashup.medias.length; _i++) {
+ _this.mashup.medias[_i].popcorn.volume(_vol);
+ }
+ }
+ }
+/*
+ options.events = this.callbacks;
+
+ _player.setup(options);
+ */
+};
+
+IriSP.PopcornReplacement.htmlMashup.prototype = new IriSP.PopcornReplacement.player("", {});
+
+IriSP.PopcornReplacement.htmlMashup.prototype.changeCurrentAnnotation = function() {
+ var _annotation = this.mashup.getAnnotationAtTime( 1000 * this.timecode );
+ if (typeof _annotation == "undefined") {
+ if (typeof this.currentMedia !== "undefined") {
+ this.currentMedia.popcorn.pause();
+ this.media.paused = true;
+ }
+ return;
+ }
+ if (_annotation !== this.currentAnnotation) {
+ this.currentAnnotation = _annotation;
+ this.segmentBegin = this.currentAnnotation.annotation.begin.getSeconds();
+ this.segmentEnd = this.currentAnnotation.annotation.end.getSeconds();
+ this.timedelta = this.segmentBegin - this.currentAnnotation.begin.getSeconds();
+ this.currentMedia = this.currentAnnotation.getMedia();
+
+ for (var _i = 0; _i < this.mashup.medias.length; _i++) {
+ if (this.mashup.medias[_i].id !== this.currentMedia.id) {
+ this.mashup.medias[_i].videoEl.hide();
+ this.mashup.medias[_i].popcorn.pause();
+ } else {
+ this.mashup.medias[_i].videoEl.show();
+ }
+ }
+ }
+ if (this.currentMedia.popcorn.readyState()) {
+ this.currentMedia.popcorn.currentTime(this.timecode + this.timedelta);
+ }
+ if (!this.media.paused) {
+ this.currentMedia.popcorn.play();
+ }
+}
/* To wrap a player the develop should create a new class derived from
the IriSP.PopcornReplacement.player and defining the correct functions */
@@ -2015,49 +2194,7 @@
break;
}
-};/* Used when Putting annotations on the platform */
-
-if (typeof IriSP.serializers === "undefined") {
- IriSP.serializers = {}
-}
-
-IriSP.serializers.ldt_annotate = {
- types : {
- annotation : {
- serialized_name : "annotations",
- serializer : function(_data, _source) {
- return {
- begin: _data.begin.milliseconds,
- end: _data.end.milliseconds,
- content: {
- data: _data.description
- },
- tags: _data.getTagTexts(),
- media: _source.unNamespace(_data.getMedia().id),
- title: _data.title,
- type_title: _data.getAnnotationType().title,
- type: _source.unNamespace(_data.getAnnotationType().id)
- }
- }
- }
- },
- serialize : function(_source) {
- var _res = {},
- _this = this;
- _source.forEach(function(_list, _typename) {
- if (typeof _this.types[_typename] !== "undefined") {
- _res[_this.types[_typename].serialized_name] = _list.map(function(_el) {
- return _this.types[_typename].serializer(_el, _source);
- });
- }
- });
- _res.meta = {
- creator: _source.creator,
- created: _source.created
- }
- return JSON.stringify(_res);
- }
-}/* LDT Platform Serializer */
+};/* LDT Platform Serializer */
if (typeof IriSP.serializers === "undefined") {
IriSP.serializers = {}
@@ -2084,11 +2221,15 @@
_res.title = _data.meta["dc:title"];
_res.description = _data.meta["dc:description"];
_res.setDuration(_data.meta["dc:duration"]);
+ _res.url = _data.meta.url;
+ if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") {
+ _res.thumbnail = _data.meta.img.src;
+ }
return _res;
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
url : _data.video,
meta : {
"dc:title" : _data.title,
@@ -2108,7 +2249,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
meta : {
"dc:title" : _data.title
}
@@ -2125,7 +2266,7 @@
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
"dc:title" : _data.title,
"dc:description" : _data.description
}
@@ -2148,7 +2289,7 @@
}
_res.color = '#' + _c;
}
- _res.setMedia(_data.media, _source);
+ _res.setMedia(_data.media);
_res.setAnnotationType(_data.meta["id-ref"]);
_res.setTags(IriSP._(_data.tags).pluck("id-ref"));
_res.setBegin(_data.begin);
@@ -2158,27 +2299,31 @@
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") {
_res.source = JSON.parse(_data.meta["dc:source"].content);
}
+ if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) {
+ _res.audio = _data.content.audio;
+ }
return _res;
},
serializer : function(_data, _source) {
return {
- id : _source.unNamespace(_data.id),
+ id : _data.id,
begin : _data.begin.milliseconds,
end : _data.end.milliseconds,
content : {
title : _data.title,
- description : _data.description
+ description : _data.description,
+ audio : _data.audio
},
- media : _source.unNamespace(_data.media.id),
+ media : _data.media.id,
meta : {
- "id-ref" : _source.unNamespace(_data.annotationType.id),
+ "id-ref" : _data.annotationType.id,
"dc:created" : IriSP.Model.dateToIso(_data.created),
"dc:creator" : _data.creator,
project : _source.projectId
},
tags : IriSP._(_data.tag.id).map(function(_id) {
return {
- "id-ref" : _source.unNamespace(_id)
+ "id-ref" : _id
}
})
}
@@ -2200,7 +2345,7 @@
"dc:title": _data.title,
"dc:description": _data.description,
segments: _data.segments.map(function(_annotation) {
- return _source.unNamespace(_id);
+ return _id;
})
}
}
@@ -2226,9 +2371,9 @@
return;
}
IriSP._(this.types).forEach(function(_type, _typename) {
- var _listdata = _data[_type.serialized_name];
+ var _listdata = _data[_type.serialized_name],
+ _list = new IriSP.Model.List(_source.directory);
if (typeof _listdata !== "undefined" && _listdata !== null) {
- var _list = new IriSP.Model.List(_source.directory);
if (_listdata.hasOwnProperty("length")) {
var _l = _listdata.length;
for (var _i = 0; _i < _l; _i++) {
@@ -2237,8 +2382,8 @@
} else {
_list.push(_type.deserializer(_listdata, _source));
}
- _source.addList(_typename, _list);
}
+ _source.addList(_typename, _list);
});
if (typeof _data.meta !== "undefined") {
@@ -2252,3 +2397,93 @@
}
}
+/* Used when Putting annotations on the platform */
+
+if (typeof IriSP.serializers === "undefined") {
+ IriSP.serializers = {}
+}
+
+IriSP.serializers.ldt_annotate = {
+ types : {
+ annotation : {
+ serialized_name : "annotations",
+ serializer : function(_data, _source) {
+ var _annType = _data.getAnnotationType();
+ return {
+ begin: _data.begin.milliseconds,
+ end: _data.end.milliseconds,
+ content: {
+ data: _data.description,
+ audio: _data.audio
+ },
+ tags: _data.getTagTexts(),
+ media: _data.getMedia().id,
+ title: _data.title,
+ type_title: _annType.title,
+ type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id )
+ }
+ }
+ }
+ },
+ serialize : function(_source) {
+ var _res = {},
+ _this = this;
+ _source.forEach(function(_list, _typename) {
+ if (typeof _this.types[_typename] !== "undefined") {
+ _res[_this.types[_typename].serialized_name] = _list.map(function(_el) {
+ return _this.types[_typename].serializer(_el, _source);
+ });
+ }
+ });
+ _res.meta = {
+ creator: _source.creator,
+ created: _source.created
+ }
+ return JSON.stringify(_res);
+ },
+ deSerialize : function(_data, _source) {
+ if (typeof _data == "string") {
+ _data = JSON.parse(_data);
+ }
+ _source.addList('tag', new IriSP.Model.List(_source.directory));
+ _source.addList('annotationType', new IriSP.Model.List(_source.directory));
+ _source.addList('annotation', new IriSP.Model.List(_source.directory));
+ if (typeof _data.annotations == "object" && _data.annotations && _data.annotations.length) {
+ var _anndata = _data.annotations[0],
+ _ann = new IriSP.Model.Annotation(_anndata.id, _source);
+ _ann.title = _anndata.content.title || "";
+ _ann.description = _anndata.content.data || "";
+ _ann.created = new Date(_data.meta.created);
+ _ann.setMedia(_anndata.media, _source);
+ var _anntypes = _source.getAnnotationTypes(true).searchByTitle(_anndata.type_title);
+ if (_anntypes.length) {
+ var _anntype = _anntypes[0];
+ } else {
+ var _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source);
+ _anntype.title = _anndata.type_title;
+ _source.getAnnotationTypes().push(_anntype);
+ }
+ _ann.setAnnotationType(_anntype.id);
+ var _tagIds = IriSP._(_anndata.tags).map(function(_title) {
+ var _tags = _source.getTags(true).searchByTitle(_title);
+ if (_tags.length) {
+ var _tag = _tags[0];
+ }
+ else {
+ _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source);
+ _tag.title = _title;
+ _source.getTags().push(_tag);
+ }
+ return _tag.id;
+ });
+ _ann.setTags(_tagIds);
+ _ann.setBegin(_anndata.begin);
+ _ann.setEnd(_anndata.end);
+ _ann.creator = _data.meta.creator;
+ if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) {
+ _ann.audio = _anndata.content.audio;
+ }
+ _source.getAnnotations().push(_ann);
+ }
+ }
+}
\ No newline at end of file