made the listWidget redraw at every timeupdate event (added a small optimization though,
to make sure that the widget isn't redrawn all the time).
--- a/src/js/pop.js Tue Jan 10 14:38:58 2012 +0100
+++ b/src/js/pop.js Tue Jan 10 16:09:30 2012 +0100
@@ -3,11 +3,7 @@
IriSP.PopcornReplacement = {
msgPump : {} /* used by jquery to receive and send messages */,
- __fake_currentTime : 0, /* when the stream is too slow, some events which depend
- on event "seeked" react to quickly and pickup the wrong currentTime.
- That's why we store the future currentTime in a var until the player
- has finished seeking */
- __faking : false
+ __delay_seek_signal : false
};
IriSP.PopcornReplacement.media = {
@@ -81,17 +77,12 @@
};
IriSP.PopcornReplacement.currentTime = function(time) {
- if (typeof(time) === "undefined") {
- if (IriSP.PopcornReplacement.__faking === true) {
- return IriSP.PopcornReplacement.__fake_currentTime;
- }
-
+ if (typeof(time) === "undefined") {
return jwplayer(IriSP.PopcornReplacement._container).getPosition();
} else {
var currentTime = +time;
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime );
- IriSP.PopcornReplacement.__fake_currentTime = currentTime;
- IriSP.PopcornReplacement.trigger("seeked");
+ IriSP.PopcornReplacement.__delay_seek_signal = true;
//return jwplayer(IriSP.PopcornReplacement._container).getPosition();
return currentTime;
}
@@ -190,14 +181,15 @@
}
+ if (IriSP.PopcornReplacement.__delay_seek_signal === true) {
+ console.log(IriSP.PopcornReplacement.currentTime());
+ IriSP.PopcornReplacement.trigger("seeked");
+ }
IriSP.PopcornReplacement.trigger("timeupdate");
};
IriSP.PopcornReplacement.__playHandler = function(event) {
- if (IriSP.PopcornReplacement.__faking === true)
- IriSP.PopcornReplacement.__faking = false;
-
IriSP.PopcornReplacement.media.paused = false;
IriSP.PopcornReplacement.trigger("play");
};
--- a/src/js/widgets/annotationsListWidget.js Tue Jan 10 14:38:58 2012 +0100
+++ b/src/js/widgets/annotationsListWidget.js Tue Jan 10 16:09:30 2012 +0100
@@ -1,5 +1,7 @@
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
IriSP.Widget.call(this, Popcorn, config, Serializer);
+ this.__counter = 0;
+ this.__oldList = [];
};
@@ -18,13 +20,7 @@
var view_type = this._serializer.getContributions();
var annotations = this._serializer._data.annotations;
var currentTime = this._Popcorn.currentTime();
-
- /* happens when the player hasn't yet loaded */
- if (typeof(currentTime) === "undefined") {
- window.setTimeout(IriSP.wrap(this, this.drawList), 4000);
- return;
- }
-
+
var list = [];
if (typeof(view_type) === "undefined") {
@@ -58,17 +54,48 @@
list.push(obj);
}
- var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
- this.selector.html(widgetMarkup);
+ var idList = IriSP.underscore.pluck(list, "id").sort();
+
+ if (idList.length !== this.__oldList.length) {
+ var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
+ this.selector.html(widgetMarkup);
+ }
+
+ var res = 1;
+ for (var i = 0; i < idList.length; i++) {
+ if (idList[i] !== this.__oldList[i])
+ res = 0;
+ break;
+ }
+
+ this.__oldList = idList; /* save for next call */
+
+ /* the two lists are equal, no need to redraw */
+ if (res === 1) {
+ return;
+ } else {
+ var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
+ this.selector.html(widgetMarkup);
+ }
+
};
IriSP.AnnotationsListWidget.prototype.draw = function() {
this.drawList();
- this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw));
- this._Popcorn.listen("seeked", IriSP.wrap(this, this.redraw));
+ this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.drawList));
+ this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw));
};
IriSP.AnnotationsListWidget.prototype.redraw = function() {
+ /* we use some kind of counter to mitigate the fact that the function
+ is supposed to be called at every timeupdate */
+/* if (this.__counter < 4) {
+ this.__counter++;
+ } else {
+ this.drawList();
+ this.__counter = 0;
+ }*/
+
this.drawList();
};
\ No newline at end of file