From 538d45ce576924400e1cd887d61a5727554f6492 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 10 Jul 2013 13:29:48 +0000 Subject: [PATCH] check if same item is in new items on update item, fire durationchanged fixes #1640 --- source/Ox.UI/js/Video/VideoElement.js | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/source/Ox.UI/js/Video/VideoElement.js b/source/Ox.UI/js/Video/VideoElement.js index e33217b7..e13a907d 100644 --- a/source/Ox.UI/js/Video/VideoElement.js +++ b/source/Ox.UI/js/Video/VideoElement.js @@ -30,16 +30,28 @@ Ox.VideoElement = function(options, self) { items: function() { self.loadedMetadata = false; loadItems(function() { - if (self.items.length != self.numberOfItems) { - self.numberOfItems = self.items.lenth; - if (self.currentItem > self.numberOfItems) { + var update = true; + self.numberOfItems = self.items.lenth; + if (self.currentItem > self.numberOfItems) { + self.currentItem = 0; + } + if (self.currentItemId != self.items[self.currentItem].id) { + // check if current item is in new items + self.items.some(function(item, i) { + if (item.id == self.currentItemId) { + self.currentItem = i; + loadNextVideo(); + update = false; + return true; + } + }); + if (update) { self.currentItem = 0; + self.currentItemId = self.items[self.currentItem].id; + setCurrentVideo(); } } - var item = self.items[self.currentItem]; - if (self.$video.attr('src') != item.src) { - setCurrentVideo(); - } + that.triggerEvent('durationchanged'); }); } }) @@ -140,6 +152,10 @@ Ox.VideoElement = function(options, self) { next(); + function getId(item) { + return item.src + '/' + item['in'] + '-' + item.out; + } + function next() { var item; if (i < items.length) { @@ -155,6 +171,7 @@ Ox.VideoElement = function(options, self) { } console.log('add item', item); currentTime += item.duration; + item.id = getId(item); i++; next() } else { @@ -165,6 +182,7 @@ Ox.VideoElement = function(options, self) { item.out = item['in'] + item.duration; } currentTime += item.duration; + item.id = getId(item); i++; next(); }); @@ -223,6 +241,7 @@ Ox.VideoElement = function(options, self) { set(); function set() { self.currentItem = item; + self.currentItemId = self.items[self.currentItem].id; setCurrentVideo(); onLoadedMetadata(self.$video, function() { that.triggerEvent('sizechange');