use serialForEach to loadItems

This commit is contained in:
j 2014-02-09 05:31:15 +00:00
parent b2426c1ac6
commit 96cbf49579

View file

@ -168,20 +168,13 @@ Ox.VideoElement = function(options, self) {
} }
function loadItems(callback) { function loadItems(callback) {
var currentTime = 0, i = 0, var currentTime = 0,
items = self.options.items.map(function(item) { items = self.options.items.map(function(item) {
return Ox.isObject(item) ? Ox.clone(item, true) : {src: item}; return Ox.isObject(item) ? Ox.clone(item, true) : {src: item};
}); });
next(); Ox.serialForEach(items,
function(item) {
function getId(item) { var callback = Ox.last(arguments);
return item.id || item.src + '/' + item['in'] + '-' + item.out;
}
function next() {
var item;
if (i < items.length) {
item = items[i];
item['in'] = item['in'] || 0; item['in'] = item['in'] || 0;
item.position = currentTime; item.position = currentTime;
if (item.out) { if (item.out) {
@ -193,8 +186,7 @@ Ox.VideoElement = function(options, self) {
} }
currentTime += item.duration; currentTime += item.duration;
item.id = getId(item); item.id = getId(item);
i++; callback()
next()
} else { } else {
Ox.getVideoInfo(item.src, function(info) { Ox.getVideoInfo(item.src, function(info) {
item.duration = info.duration; item.duration = info.duration;
@ -203,15 +195,18 @@ Ox.VideoElement = function(options, self) {
} }
currentTime += item.duration; currentTime += item.duration;
item.id = getId(item); item.id = getId(item);
i++; callback();
next();
}); });
} }
} else { },
function() {
self.items = items; self.items = items;
self.numberOfItems = self.items.length; self.numberOfItems = self.items.length;
callback && callback(); callback && callback();
} }
);
function getId(item) {
return item.id || item.src + '/' + item['in'] + '-' + item.out;
} }
} }