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