'use strict'; /*@ Ox.VideoElement VideoElement Object options Options object autoplay autoplay items array of objects with src,in,out,duration loop loop playback self Shared private variable ([options[, self]]) -> VideoElement Object loadedmetadata loadedmetadata itemchange itemchange seeked seeked seeking seeking sizechange sizechange ended ended @*/ Ox.VideoElement = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ autoplay: false, loop: false, items: [] }) .options(options || {}) .update({ items: function() { self.loadedMetadata = false; loadItems(function() { self.loadedMetadata = true; var update = true; if (self.currentItem >= self.numberOfItems) { self.currentItem = 0; } if (!self.numberOfItems) { self.video.src = ''; that.triggerEvent('durationchange', { duration: that.duration() }); } else { 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; } } if (!update) { that.triggerEvent('seeked'); that.triggerEvent('durationchange', { duration: that.duration() }); } else { setCurrentVideo(function() { that.triggerEvent('seeked'); that.triggerEvent('durationchange', { duration: that.duration() }); }); } } }); } }) .css({width: '100%', height: '100%'}); Ox.Log('Video', 'VIDEO ELEMENT OPTIONS', self.options); self.currentItem = 0; self.currentTime = 0; self.currentVideo = 0; self.items = []; self.loadedMetadata = false; self.paused = true; self.seeking = false; self.loading = true; self.buffering = true; self.$videos = [getVideo(), getVideo()]; self.$video = self.$videos[self.currentVideo]; self.video = self.$video[0]; self.$brightness = $('
').css({ width: '100%', height: '100%', background: 'rgb(0, 0, 0)', opacity: 0 }) .appendTo(that); self.timeupdate = setInterval(function() { if (!self.paused && !self.loading && self.loadedMetadata && self.items[self.currentItem] && self.items[self.currentItem].out && self.video.currentTime >= self.items[self.currentItem].out) { setCurrentItem(self.currentItem + 1); } }, 30); loadItems(function() { setCurrentItem(0); self.options.autoplay && setTimeout(function() { that.play(); }); }); function getCurrentTime() { var item = self.items[self.currentItem]; return self.seeking || self.loading ? self.currentTime : item ? item.position + self.video.currentTime - item['in'] : 0; } function getset(key, value) { var ret; if (Ox.isUndefined(value)) { ret = self.video[key]; } else { self.video[key] = value; ret = that; } return ret; } function getVideo() { return $('