diff -r be1c7b812f55 -r 4bdadca1cd5a integration/js/tagplayer.js --- a/integration/js/tagplayer.js Wed Jan 09 16:51:45 2013 +0100 +++ b/integration/js/tagplayer.js Tue Jan 15 17:16:51 2013 +0100 @@ -3,7 +3,8 @@ project = directory.remoteSource({ url: IriSP.endpoints.mashup_by_tag, url_params: { - tag: opts.tag + tag: '"' + opts.tag + '"', + sort: "weight" }, serializer: IriSP.serializers.ldt }), @@ -13,7 +14,9 @@ currentSegment, currentMedia, globalTags = {}, - seqCount; + seqCount, + mediasInDom = [], + MAX_LOADED_VIDEOS = 2; var ratio = 2.37; @@ -238,9 +241,7 @@ return; } mashup.getMedias().forEach(function(m) { - m.show = function() { - addMedia(m); - } + addMedia(m); }); seqCount = mashup.segments.length; var html = mashup.segments.map(function(s, i) { @@ -285,6 +286,19 @@ currentIndex = n; currentSegment = mashup.segments[n].annotation; currentMedia = currentSegment.getMedia(); + var followingMedias = []; + for (var i = n; i < mashup.segments.length; i++) { + followingMedias.push(mashup.segments[i].getMedia()); + } + followingMedias = _(followingMedias).uniq().slice(0, MAX_LOADED_VIDEOS); + var mediasToRemove = _(mediasInDom).difference(followingMedias); + _(mediasToRemove).each(function(m) { + m.removeFromDom(); + }); + followingMedias = _(followingMedias).difference(mediasInDom); + _(followingMedias).each(function(m) { + m.addToDom(); + }); mashup.getMedias().forEach(function(m) { if (m === currentMedia) { m.show(); @@ -292,6 +306,7 @@ m.hide(); } }); + console.log("There are now",mediasInDom.length,'~',$("video").length,"