check if same item is in new items on update item, fire durationchanged fixes #1640

This commit is contained in:
j 2013-07-10 13:29:48 +00:00
parent 1b1fb49eb8
commit 538d45ce57

View file

@ -30,16 +30,28 @@ Ox.VideoElement = function(options, self) {
items: function() { items: function() {
self.loadedMetadata = false; self.loadedMetadata = false;
loadItems(function() { loadItems(function() {
if (self.items.length != self.numberOfItems) { var update = true;
self.numberOfItems = self.items.lenth; self.numberOfItems = self.items.lenth;
if (self.currentItem > self.numberOfItems) { 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.currentItem = 0;
self.currentItemId = self.items[self.currentItem].id;
setCurrentVideo();
} }
} }
var item = self.items[self.currentItem]; that.triggerEvent('durationchanged');
if (self.$video.attr('src') != item.src) {
setCurrentVideo();
}
}); });
} }
}) })
@ -140,6 +152,10 @@ Ox.VideoElement = function(options, self) {
next(); next();
function getId(item) {
return item.src + '/' + item['in'] + '-' + item.out;
}
function next() { function next() {
var item; var item;
if (i < items.length) { if (i < items.length) {
@ -155,6 +171,7 @@ Ox.VideoElement = function(options, self) {
} }
console.log('add item', item); console.log('add item', item);
currentTime += item.duration; currentTime += item.duration;
item.id = getId(item);
i++; i++;
next() next()
} else { } else {
@ -165,6 +182,7 @@ Ox.VideoElement = function(options, self) {
item.out = item['in'] + item.duration; item.out = item['in'] + item.duration;
} }
currentTime += item.duration; currentTime += item.duration;
item.id = getId(item);
i++; i++;
next(); next();
}); });
@ -223,6 +241,7 @@ Ox.VideoElement = function(options, self) {
set(); set();
function set() { function set() {
self.currentItem = item; self.currentItem = item;
self.currentItemId = self.items[self.currentItem].id;
setCurrentVideo(); setCurrentVideo();
onLoadedMetadata(self.$video, function() { onLoadedMetadata(self.$video, function() {
that.triggerEvent('sizechange'); that.triggerEvent('sizechange');