diff --git a/static/js/pandora/pandora.js b/static/js/pandora/pandora.js index f6967bd4..1170bee0 100644 --- a/static/js/pandora/pandora.js +++ b/static/js/pandora/pandora.js @@ -144,17 +144,26 @@ pandora.getListData = function() { return data; }; -pandora.getVideoPartAndPosition = function(durations, position) { - var duration = 0, ret; - Ox.forEach(durations, function(d, i) { - if (duration + d > position) { - ret = { - part: i, - position: position - duration +pandora.getVideoPartsAndPoints = function(durations, points) { + var parts = durations.length, + offsets = Ox.range(parts).map(function(i) { + return Ox.sum(Ox.sub(durations, 0, i)); + }), + ret = { + parts: [], + points: [] + }; + points.forEach(function(point, i) { + Ox.loop(parts - 1, -1, -1, function(i) { + if (offsets[i] <= point) { + ret.parts[i] = i; + return false; } - return false; - } - duration += d; + }); + }); + ret.parts = Ox.unique(ret.parts); + ret.points = points.map(function(point) { + return point - offsets[ret.parts[0]]; }); return ret; }; diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 931761f1..cf146f32 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -233,18 +233,18 @@ pandora.ui.list = function() { // fixme: remove view argument if ($img.length) { var width = parseInt($img.css('width')), height = parseInt($img.css('height')); - pandora.api.get({id: item, keys: ['parts']}, function(result) { - var inPoint = that.value(id, 'in'), - outPoint = that.value(id, 'out'), + pandora.api.get({id: item, keys: ['durations']}, function(result) { + var points = [that.value(id, 'in'), that.value(id, 'out')], + partsAndPoints = pandora.getVideoPartsAndPoints(result.data.durations, points), $player = Ox.VideoPlayer({ height: height, - 'in': inPoint, - out: outPoint, + 'in': partsAndPoints.points[0], + out: partsAndPoints.points[1], paused: true, playInToOut: true, - poster: '/' + item + '/' + height + 'p' + that.value(id, 'in') + '.jpg', + poster: '/' + item + '/' + height + 'p' + points[0] + '.jpg', width: width, - video: Ox.range(result.data.parts).map(function(i) { + video: partsAndPoints.parts.map(function(i) { return '/' + item + '/96p' + (i + 1) + '.' + pandora.user.videoFormat }) })