'use strict'; /*@ Ox.VideoElement VideoElement Object options Options object autoplay autoplay items array of objects with src,in,out,duration loop loop playback playbackRate playback rate 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, playbackRate: 1, 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() }); }); } } }); }, playbackRate: function() { self.video.playbackRate = self.options.playbackRate; } }) .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); // mobile browsers only allow playing media elements after user interaction if (mediaPlaybackRequiresUserGesture()) { window.addEventListener('keydown', removeBehaviorsRestrictions); window.addEventListener('mousedown', removeBehaviorsRestrictions); window.addEventListener('touchstart', removeBehaviorsRestrictions); setTimeout(function() { that.triggerEvent('requiresusergesture'); }) } else { setSource(); } 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 $('