2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.VideoElement <f> VideoElement Object
|
2012-07-04 11:29:18 +00:00
|
|
|
options <o> Options object
|
2013-07-09 22:48:22 +00:00
|
|
|
autoplay <b|false> autoplay
|
2013-07-14 09:16:39 +00:00
|
|
|
items <a|[]> array of objects with src,in,out,duration
|
2014-03-13 18:53:02 +00:00
|
|
|
loop <b|false> loop playback
|
2016-03-29 12:26:04 +00:00
|
|
|
playbackRate <n|1> playback rate
|
2012-07-04 11:29:18 +00:00
|
|
|
self <o> Shared private variable
|
2012-05-31 10:32:54 +00:00
|
|
|
([options[, self]]) -> <o:Ox.Element> VideoElement Object
|
2012-06-17 22:38:26 +00:00
|
|
|
loadedmetadata <!> loadedmetadata
|
2013-07-09 22:48:22 +00:00
|
|
|
itemchange <!> itemchange
|
2012-06-17 22:38:26 +00:00
|
|
|
seeked <!> seeked
|
|
|
|
seeking <!> seeking
|
|
|
|
sizechange <!> sizechange
|
|
|
|
ended <!> ended
|
2011-09-14 14:34:33 +00:00
|
|
|
@*/
|
|
|
|
|
2016-07-26 16:55:55 +00:00
|
|
|
(function() {
|
|
|
|
var queue = [],
|
|
|
|
queueSize = 100,
|
|
|
|
restrictedElements = [],
|
|
|
|
requiresUserGesture = mediaPlaybackRequiresUserGesture(),
|
|
|
|
unblock = [];
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.VideoElement = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
2011-08-19 10:45:36 +00:00
|
|
|
var that = Ox.Element({}, self)
|
2012-12-09 00:42:57 +00:00
|
|
|
.defaults({
|
|
|
|
autoplay: false,
|
2013-07-09 22:48:22 +00:00
|
|
|
loop: false,
|
2016-03-29 12:26:04 +00:00
|
|
|
playbackRate: 1,
|
2013-07-09 22:48:22 +00:00
|
|
|
items: []
|
2012-12-09 00:42:57 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2013-07-09 22:48:22 +00:00
|
|
|
.update({
|
|
|
|
items: function() {
|
|
|
|
self.loadedMetadata = false;
|
|
|
|
loadItems(function() {
|
2014-02-08 18:43:46 +00:00
|
|
|
self.loadedMetadata = true;
|
2013-07-10 13:29:48 +00:00
|
|
|
var update = true;
|
2013-07-13 23:06:07 +00:00
|
|
|
if (self.currentItem >= self.numberOfItems) {
|
2013-07-10 13:29:48 +00:00
|
|
|
self.currentItem = 0;
|
|
|
|
}
|
2013-07-14 09:16:39 +00:00
|
|
|
if (!self.numberOfItems) {
|
|
|
|
self.video.src = '';
|
|
|
|
that.triggerEvent('durationchange', {
|
|
|
|
duration: that.duration()
|
2013-07-10 13:29:48 +00:00
|
|
|
});
|
2013-07-14 09:16:39 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
2014-02-08 18:43:46 +00:00
|
|
|
if (!update) {
|
2013-07-14 10:41:30 +00:00
|
|
|
that.triggerEvent('seeked');
|
2013-07-14 09:16:39 +00:00
|
|
|
that.triggerEvent('durationchange', {
|
|
|
|
duration: that.duration()
|
|
|
|
});
|
2014-02-13 06:47:10 +00:00
|
|
|
} else {
|
|
|
|
setCurrentVideo(function() {
|
|
|
|
that.triggerEvent('seeked');
|
|
|
|
that.triggerEvent('durationchange', {
|
|
|
|
duration: that.duration()
|
|
|
|
});
|
|
|
|
});
|
2014-02-08 18:43:46 +00:00
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
|
|
|
});
|
2016-03-29 12:26:04 +00:00
|
|
|
},
|
|
|
|
playbackRate: function() {
|
|
|
|
self.video.playbackRate = self.options.playbackRate;
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
|
|
|
})
|
2012-12-09 00:42:57 +00:00
|
|
|
.css({width: '100%', height: '100%'});
|
2011-08-19 10:45:36 +00:00
|
|
|
|
2012-02-16 16:35:30 +00:00
|
|
|
Ox.Log('Video', 'VIDEO ELEMENT OPTIONS', self.options);
|
2011-08-19 10:45:36 +00:00
|
|
|
|
2013-07-09 22:48:22 +00:00
|
|
|
self.currentItem = 0;
|
|
|
|
self.currentTime = 0;
|
|
|
|
self.currentVideo = 0;
|
2015-03-19 14:21:32 +00:00
|
|
|
self.items = [];
|
2012-02-17 12:36:26 +00:00
|
|
|
self.loadedMetadata = false;
|
2011-08-19 10:45:36 +00:00
|
|
|
self.paused = true;
|
2013-07-09 22:48:22 +00:00
|
|
|
self.seeking = false;
|
2014-02-08 18:43:46 +00:00
|
|
|
self.loading = true;
|
2014-02-12 15:29:35 +00:00
|
|
|
self.buffering = true;
|
2013-07-09 22:48:22 +00:00
|
|
|
self.$videos = [getVideo(), getVideo()];
|
|
|
|
self.$video = self.$videos[self.currentVideo];
|
|
|
|
self.video = self.$video[0];
|
|
|
|
self.$brightness = $('<div>').css({
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
background: 'rgb(0, 0, 0)',
|
|
|
|
opacity: 0
|
|
|
|
})
|
|
|
|
.appendTo(that);
|
2014-02-09 06:16:57 +00:00
|
|
|
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);
|
2011-08-20 09:48:28 +00:00
|
|
|
|
2016-05-17 15:40:31 +00:00
|
|
|
// mobile browsers only allow playing media elements after user interaction
|
2016-07-26 16:55:55 +00:00
|
|
|
if (restrictedElements.length > 0) {
|
|
|
|
unblock.push(setSource);
|
2016-05-17 15:40:31 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
that.triggerEvent('requiresusergesture');
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setSource();
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-08-19 10:45:36 +00:00
|
|
|
function getCurrentTime() {
|
2013-07-09 22:48:22 +00:00
|
|
|
var item = self.items[self.currentItem];
|
2014-02-08 18:43:46 +00:00
|
|
|
return self.seeking || self.loading
|
2013-07-09 22:48:22 +00:00
|
|
|
? self.currentTime
|
2013-07-14 09:16:39 +00:00
|
|
|
: item ? item.position + self.video.currentTime - item['in'] : 0;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 10:45:36 +00:00
|
|
|
function getset(key, value) {
|
|
|
|
var ret;
|
|
|
|
if (Ox.isUndefined(value)) {
|
2012-02-16 16:35:30 +00:00
|
|
|
ret = self.video[key];
|
2011-08-19 10:45:36 +00:00
|
|
|
} else {
|
|
|
|
self.video[key] = value;
|
|
|
|
ret = that;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-08-19 10:45:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:48:22 +00:00
|
|
|
function getVideo() {
|
2016-07-26 16:55:55 +00:00
|
|
|
return getVideoElement()
|
2013-07-09 22:48:22 +00:00
|
|
|
.css({position: 'absolute'})
|
|
|
|
.on({
|
|
|
|
ended: function() {
|
|
|
|
if (self.video == this) {
|
|
|
|
setCurrentItem(self.currentItem + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadedmetadata: function() {
|
|
|
|
// metadata loaded in loadItems
|
|
|
|
},
|
|
|
|
progress: function() {
|
2014-02-12 15:29:35 +00:00
|
|
|
// stop buffering if buffered to end point
|
|
|
|
if (self.video == this && self.buffering) {
|
|
|
|
var item = self.items[self.currentItem];
|
|
|
|
Ox.range(self.video.buffered.length).forEach(function(i) {
|
|
|
|
if (self.video.buffered.start(i) <= item['in']
|
|
|
|
&& self.video.buffered.end(i) >= item.out) {
|
|
|
|
self.video.preload = 'none';
|
|
|
|
self.buffering = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
},
|
|
|
|
seeking: function() {
|
|
|
|
//seeking event triggered in setCurrentTime
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
if (self.video == this) {
|
|
|
|
self.video.pause();
|
2011-08-20 09:48:28 +00:00
|
|
|
that.triggerEvent('ended');
|
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
2011-10-22 21:03:42 +00:00
|
|
|
})
|
2013-07-09 22:48:22 +00:00
|
|
|
.attr({
|
|
|
|
preload: 'auto'
|
|
|
|
})
|
|
|
|
.hide()
|
2012-06-26 16:21:39 +00:00
|
|
|
.appendTo(that);
|
2011-08-20 09:48:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 16:55:55 +00:00
|
|
|
function getVideoElement() {
|
|
|
|
var video;
|
|
|
|
if (requiresUserGesture) {
|
|
|
|
if (queue.length) {
|
|
|
|
video = queue.pop();
|
|
|
|
} else {
|
|
|
|
video = document.createElement('video');
|
|
|
|
restrictedElements.push(video);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
video = document.createElement('video');
|
|
|
|
}
|
|
|
|
return $(video);
|
|
|
|
};
|
|
|
|
|
2014-02-12 09:11:59 +00:00
|
|
|
function isReady($video, callback) {
|
|
|
|
if ($video[0].seeking) {
|
2014-12-26 23:44:31 +00:00
|
|
|
that.triggerEvent('seeking');
|
2014-02-12 09:11:59 +00:00
|
|
|
$video.one('seeked', function(event) {
|
2014-12-26 23:44:31 +00:00
|
|
|
that.triggerEvent('seeked');
|
2014-02-12 09:11:59 +00:00
|
|
|
callback($video[0]);
|
|
|
|
});
|
|
|
|
} else if ($video[0].readyState) {
|
|
|
|
callback($video[0]);
|
|
|
|
} else {
|
2014-12-26 23:44:31 +00:00
|
|
|
that.triggerEvent('seeking');
|
2014-02-12 09:11:59 +00:00
|
|
|
$video.one('loadedmetadata', function(event) {
|
|
|
|
callback($video[0]);
|
|
|
|
});
|
2014-12-26 23:44:31 +00:00
|
|
|
$video.one('seeked', function(event) {
|
|
|
|
that.triggerEvent('seeked');
|
|
|
|
});
|
2014-02-12 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:48:22 +00:00
|
|
|
function loadItems(callback) {
|
2014-02-09 05:31:15 +00:00
|
|
|
var currentTime = 0,
|
2013-07-09 22:48:22 +00:00
|
|
|
items = self.options.items.map(function(item) {
|
|
|
|
return Ox.isObject(item) ? Ox.clone(item, true) : {src: item};
|
|
|
|
});
|
2014-02-09 05:31:15 +00:00
|
|
|
Ox.serialForEach(items,
|
|
|
|
function(item) {
|
|
|
|
var callback = Ox.last(arguments);
|
2013-07-09 22:48:22 +00:00
|
|
|
item['in'] = item['in'] || 0;
|
2013-07-14 09:16:39 +00:00
|
|
|
item.position = currentTime;
|
2013-07-09 22:48:22 +00:00
|
|
|
if (item.out) {
|
|
|
|
item.duration = item.out - item['in'];
|
|
|
|
}
|
|
|
|
if (item.duration) {
|
2013-07-14 17:46:03 +00:00
|
|
|
if (!item.out) {
|
2014-02-12 15:31:11 +00:00
|
|
|
item.out = item.duration;
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
|
|
|
currentTime += item.duration;
|
2013-07-10 13:29:48 +00:00
|
|
|
item.id = getId(item);
|
2014-02-09 05:31:15 +00:00
|
|
|
callback()
|
2013-07-09 22:48:22 +00:00
|
|
|
} else {
|
|
|
|
Ox.getVideoInfo(item.src, function(info) {
|
|
|
|
item.duration = info.duration;
|
2013-07-14 17:46:03 +00:00
|
|
|
if (!item.out) {
|
2014-02-12 15:31:11 +00:00
|
|
|
item.out = item.duration;
|
2012-02-17 12:36:26 +00:00
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
currentTime += item.duration;
|
2013-07-10 13:29:48 +00:00
|
|
|
item.id = getId(item);
|
2014-02-09 05:31:15 +00:00
|
|
|
callback();
|
2012-02-17 12:36:26 +00:00
|
|
|
});
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
2014-02-09 05:31:15 +00:00
|
|
|
},
|
|
|
|
function() {
|
2013-07-09 22:48:22 +00:00
|
|
|
self.items = items;
|
|
|
|
self.numberOfItems = self.items.length;
|
|
|
|
callback && callback();
|
|
|
|
}
|
2014-02-09 05:31:15 +00:00
|
|
|
);
|
|
|
|
function getId(item) {
|
|
|
|
return item.id || item.src + '/' + item['in'] + '-' + item.out;
|
2012-02-17 12:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 22:48:22 +00:00
|
|
|
function loadNextVideo() {
|
2013-07-22 21:46:43 +00:00
|
|
|
if (self.numberOfItems <= 1) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
var item = self.items[self.currentItem],
|
|
|
|
nextItem = Ox.mod(self.currentItem + 1, self.numberOfItems),
|
|
|
|
next = self.items[nextItem],
|
|
|
|
$nextVideo = self.$videos[Ox.mod(self.currentVideo + 1, self.$videos.length)],
|
|
|
|
nextVideo = $nextVideo[0];
|
2014-02-10 10:35:49 +00:00
|
|
|
$nextVideo.one('loadedmetadata', function() {
|
|
|
|
if (self.video != nextVideo) {
|
|
|
|
nextVideo.currentTime = next['in'] || 0;
|
|
|
|
}
|
2012-02-17 12:36:26 +00:00
|
|
|
});
|
2014-02-10 10:35:49 +00:00
|
|
|
nextVideo.src = next.src;
|
2014-02-12 15:29:35 +00:00
|
|
|
nextVideo.preload = 'auto';
|
2012-02-17 12:36:26 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 09:48:28 +00:00
|
|
|
function setCurrentItem(item) {
|
2013-07-09 22:48:22 +00:00
|
|
|
Ox.Log('Video', 'sCI', item, self.numberOfItems);
|
2011-08-20 09:48:28 +00:00
|
|
|
var interval;
|
2013-07-14 17:46:03 +00:00
|
|
|
if (item >= self.numberOfItems || item < 0) {
|
2013-07-09 22:48:22 +00:00
|
|
|
if (self.options.loop) {
|
|
|
|
item = Ox.mod(item, self.numberOfItems);
|
|
|
|
} else {
|
2013-07-14 15:26:37 +00:00
|
|
|
self.seeking = false;
|
2013-07-09 22:48:22 +00:00
|
|
|
self.ended = true;
|
|
|
|
self.paused = true;
|
|
|
|
self.video && self.video.pause();
|
|
|
|
that.triggerEvent('ended');
|
|
|
|
return;
|
|
|
|
}
|
2011-08-20 09:48:28 +00:00
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
self.video && self.video.pause();
|
2014-02-08 18:43:46 +00:00
|
|
|
self.currentItem = item;
|
|
|
|
self.currentItemId = self.items[self.currentItem].id;
|
|
|
|
setCurrentVideo(function() {
|
|
|
|
if (!self.loadedMetadata) {
|
|
|
|
self.loadedMetadata = true;
|
|
|
|
that.triggerEvent('loadedmetadata');
|
|
|
|
}
|
2014-02-10 10:35:49 +00:00
|
|
|
Ox.Log('Video', 'sCI', 'trigger itemchange',
|
|
|
|
self.items[self.currentItem]['in'], self.video.currentTime, self.video.seeking);
|
2014-02-08 18:43:46 +00:00
|
|
|
that.triggerEvent('sizechange');
|
|
|
|
that.triggerEvent('itemchange', {
|
|
|
|
item: self.currentItem
|
2013-07-09 22:48:22 +00:00
|
|
|
});
|
2014-02-08 18:43:46 +00:00
|
|
|
});
|
2011-08-20 09:48:28 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:43:46 +00:00
|
|
|
function setCurrentVideo(callback) {
|
2012-02-16 16:35:30 +00:00
|
|
|
var css = {},
|
|
|
|
muted = false,
|
2013-07-09 22:48:22 +00:00
|
|
|
volume = 1,
|
|
|
|
item = self.items[self.currentItem],
|
|
|
|
next;
|
|
|
|
Ox.Log('Video', 'sCV', item);
|
2011-08-19 10:45:36 +00:00
|
|
|
['left', 'top', 'width', 'height'].forEach(function(key) {
|
2013-07-09 22:48:22 +00:00
|
|
|
css[key] = self.$videos[self.currentVideo].css(key);
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
2014-02-08 18:43:46 +00:00
|
|
|
self.currentTime = item.position;
|
|
|
|
self.loading = true;
|
2011-08-20 09:48:28 +00:00
|
|
|
if (self.video) {
|
2013-07-09 22:48:22 +00:00
|
|
|
self.$videos[self.currentVideo].hide();
|
2011-08-23 08:14:22 +00:00
|
|
|
self.video.pause();
|
2012-02-16 16:35:30 +00:00
|
|
|
volume = self.video.volume;
|
|
|
|
muted = self.video.muted;
|
2011-08-20 09:48:28 +00:00
|
|
|
}
|
2013-07-09 22:48:22 +00:00
|
|
|
self.currentVideo = Ox.mod(self.currentVideo + 1, self.$videos.length);
|
|
|
|
self.$video = self.$videos[self.currentVideo];
|
2011-08-19 10:45:36 +00:00
|
|
|
self.video = self.$video[0];
|
2013-07-09 22:48:22 +00:00
|
|
|
if (self.$video.attr('src') != item.src) {
|
2014-02-08 18:43:46 +00:00
|
|
|
self.loadedMetadata && Ox.Log('Video', 'caching next item failed, reset src');
|
2013-07-09 22:48:22 +00:00
|
|
|
self.video.src = item.src;
|
2014-02-12 15:29:35 +00:00
|
|
|
self.video.preload = 'auto';
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
2012-02-16 16:35:30 +00:00
|
|
|
self.video.volume = volume;
|
|
|
|
self.video.muted = muted;
|
2016-03-29 12:26:04 +00:00
|
|
|
self.video.playbackRate = self.options.playbackRate;
|
2014-02-07 05:08:17 +00:00
|
|
|
self.$video.css(css);
|
2014-02-12 15:29:35 +00:00
|
|
|
self.buffering = true;
|
2014-02-10 10:35:49 +00:00
|
|
|
Ox.Log('Video', 'sCV', self.video.src, item['in'],
|
2014-02-10 09:32:08 +00:00
|
|
|
self.video.currentTime, self.video.seeking);
|
2014-02-12 09:11:59 +00:00
|
|
|
isReady(self.$video, function(video) {
|
2014-02-08 12:32:45 +00:00
|
|
|
self.$video.one('seeked', function() {
|
2016-05-17 15:40:31 +00:00
|
|
|
Ox.Log('Video', 'sCV', 'seeked callback');
|
2014-02-08 18:43:46 +00:00
|
|
|
self.loading = false;
|
|
|
|
!self.paused && self.video.play();
|
2014-02-08 12:32:45 +00:00
|
|
|
self.$video.show();
|
2014-02-08 18:43:46 +00:00
|
|
|
callback && callback();
|
|
|
|
loadNextVideo();
|
2014-02-08 12:32:45 +00:00
|
|
|
});
|
2014-02-11 09:04:08 +00:00
|
|
|
if (!self.seeking) {
|
|
|
|
Ox.Log('Video', 'sCV set in', video.src, item['in'] || 0, video.currentTime, video.seeking);
|
|
|
|
video.currentTime = item['in'] || 0;
|
2016-05-17 15:40:31 +00:00
|
|
|
if (self.paused) {
|
2016-08-23 12:06:36 +00:00
|
|
|
var promise = self.video.play();
|
|
|
|
if (promise) {
|
|
|
|
promise.then(function() {
|
|
|
|
self.video.pause();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.video.pause();
|
|
|
|
}
|
2016-05-17 15:40:31 +00:00
|
|
|
}
|
2014-02-11 09:04:08 +00:00
|
|
|
}
|
2014-02-08 18:43:46 +00:00
|
|
|
});
|
2013-07-09 22:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setCurrentItemTime(currentTime) {
|
2014-02-08 18:43:46 +00:00
|
|
|
Ox.Log('Video', 'sCIT', currentTime, self.video.currentTime,
|
|
|
|
'delta', currentTime - self.video.currentTime);
|
2014-02-12 09:11:59 +00:00
|
|
|
isReady(self.$video, function(video) {
|
2014-02-10 10:35:49 +00:00
|
|
|
if (self.video == video) {
|
|
|
|
if(self.seeking) {
|
|
|
|
self.$video.one('seeked', function() {
|
|
|
|
that.triggerEvent('seeked');
|
|
|
|
self.seeking = false;
|
|
|
|
});
|
|
|
|
}
|
2014-02-08 18:43:46 +00:00
|
|
|
video.currentTime = currentTime;
|
2014-02-10 10:35:49 +00:00
|
|
|
}
|
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 10:45:36 +00:00
|
|
|
function setCurrentTime(time) {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('Video', 'sCT', time);
|
2013-07-09 22:48:22 +00:00
|
|
|
var currentTime, currentItem;
|
|
|
|
self.items.forEach(function(item, i) {
|
2013-07-14 09:16:39 +00:00
|
|
|
if (time >= item.position
|
|
|
|
&& time < item.position + item.duration) {
|
2013-07-09 22:48:22 +00:00
|
|
|
currentItem = i;
|
2013-07-14 09:16:39 +00:00
|
|
|
currentTime = time - item.position + item['in'];
|
2013-07-09 22:48:22 +00:00
|
|
|
return false;
|
2011-08-19 10:45:36 +00:00
|
|
|
}
|
|
|
|
});
|
2013-07-14 17:46:03 +00:00
|
|
|
if (self.items.length) {
|
2013-07-14 09:16:39 +00:00
|
|
|
// Set to end of items if time > duration
|
2013-07-14 17:46:03 +00:00
|
|
|
if (Ox.isUndefined(currentItem) && Ox.isUndefined(currentTime)) {
|
2014-02-06 15:04:47 +00:00
|
|
|
currentItem = self.items.length - 1;
|
2013-07-14 09:16:39 +00:00
|
|
|
currentTime = self.items[currentItem].duration + self.items[currentItem]['in'];
|
|
|
|
}
|
|
|
|
Ox.Log('Video', 'sCT', time, '=>', currentItem, currentTime);
|
|
|
|
if (currentItem != self.currentItem) {
|
|
|
|
setCurrentItem(currentItem);
|
|
|
|
}
|
|
|
|
self.seeking = true;
|
|
|
|
self.currentTime = time;
|
|
|
|
that.triggerEvent('seeking');
|
|
|
|
setCurrentItemTime(currentTime);
|
|
|
|
} else {
|
|
|
|
self.currentTime = 0;
|
2013-03-02 08:56:15 +00:00
|
|
|
}
|
2011-08-20 09:48:28 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 15:40:31 +00:00
|
|
|
function setSource() {
|
|
|
|
Ox.Log('Video', 'self.loadedMetadata', self.loadedMetadata);
|
|
|
|
self.loadedMetadata = false;
|
|
|
|
loadItems(function() {
|
|
|
|
setCurrentItem(0);
|
|
|
|
self.options.autoplay && setTimeout(function() {
|
|
|
|
that.play();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
animate <f> animate
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.animate = function() {
|
|
|
|
self.$video.animate.apply(self.$video, arguments);
|
|
|
|
return that;
|
2011-09-14 14:34:33 +00:00
|
|
|
};
|
2011-08-19 10:45:36 +00:00
|
|
|
|
2011-10-22 21:03:42 +00:00
|
|
|
/*@
|
|
|
|
brightness <f> get/set brightness
|
|
|
|
@*/
|
|
|
|
that.brightness = function() {
|
|
|
|
var ret;
|
|
|
|
if (arguments.length == 0) {
|
|
|
|
ret = 1 - parseFloat(self.$brightness.css('opacity'));
|
|
|
|
} else {
|
|
|
|
self.$brightness.css({opacity: 1 - arguments[0]});
|
|
|
|
ret = that;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
buffered <f> buffered
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.buffered = function() {
|
|
|
|
return self.video.buffered;
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
currentTime <f> get/set currentTime
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.currentTime = function() {
|
|
|
|
var ret;
|
|
|
|
if (arguments.length == 0) {
|
|
|
|
ret = getCurrentTime();
|
|
|
|
} else {
|
2013-07-14 15:26:37 +00:00
|
|
|
self.ended = false;
|
2011-08-19 10:45:36 +00:00
|
|
|
setCurrentTime(arguments[0]);
|
|
|
|
ret = that;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
css <f> css
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.css = function() {
|
2013-07-09 22:48:22 +00:00
|
|
|
self.$video.css.apply(self.$video, arguments);
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
duration <f> duration
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.duration = function() {
|
2013-07-09 22:48:22 +00:00
|
|
|
return self.items ? Ox.sum(self.items.map(function(item) {
|
|
|
|
return item.duration;
|
|
|
|
})) : NaN;
|
2011-08-19 10:45:36 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
muted <f> get/set muted
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.muted = function() {
|
2011-08-19 10:45:36 +00:00
|
|
|
return getset('muted', arguments[0]);
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
pause <f> pause
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.pause = function() {
|
2011-08-19 10:45:36 +00:00
|
|
|
self.paused = true;
|
2011-04-22 22:03:10 +00:00
|
|
|
self.video.pause();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
play <f> play
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.play = function() {
|
2011-08-19 14:44:03 +00:00
|
|
|
if (self.ended) {
|
|
|
|
that.currentTime(0);
|
|
|
|
}
|
2014-04-10 12:50:12 +00:00
|
|
|
isReady(self.$video, function(video) {
|
|
|
|
self.ended = false;
|
|
|
|
self.paused = false;
|
|
|
|
self.seeking = false;
|
|
|
|
video.play();
|
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2014-09-23 19:03:32 +00:00
|
|
|
that.removeElement = function() {
|
2014-09-24 20:32:08 +00:00
|
|
|
self.currentTime = getCurrentTime();
|
|
|
|
self.loading = true;
|
2014-02-09 06:16:57 +00:00
|
|
|
clearInterval(self.timeupdate);
|
2014-02-09 06:06:43 +00:00
|
|
|
//Chrome does not properly release resources, reset manually
|
|
|
|
//http://code.google.com/p/chromium/issues/detail?id=31014
|
|
|
|
self.$videos.forEach(function($video) {
|
|
|
|
$video.attr({src: ''});
|
|
|
|
});
|
2014-09-23 19:03:32 +00:00
|
|
|
return Ox.Element.prototype.removeElement.apply(that, arguments);
|
2014-09-20 10:30:14 +00:00
|
|
|
};
|
2014-02-09 06:06:43 +00:00
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
videoHeight <f> get videoHeight
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.videoHeight = function() {
|
|
|
|
return self.video.videoHeight;
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
videoWidth <f> get videoWidth
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.videoWidth = function() {
|
|
|
|
return self.video.videoWidth;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-09-14 14:34:33 +00:00
|
|
|
/*@
|
|
|
|
volume <f> get/set volume
|
|
|
|
@*/
|
2011-08-19 10:45:36 +00:00
|
|
|
that.volume = function(value) {
|
|
|
|
return getset('volume', arguments[0]);
|
2012-02-16 16:35:30 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|
2016-07-26 16:55:55 +00:00
|
|
|
|
|
|
|
// mobile browsers only allow playing media elements after user interaction
|
|
|
|
|
|
|
|
function mediaPlaybackRequiresUserGesture() {
|
|
|
|
// test if play() is ignored when not called from an input event handler
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.play();
|
|
|
|
return video.paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function removeBehaviorsRestrictions() {
|
|
|
|
//Ox.Log('Video', 'remove restrictions on video', self.$video);
|
|
|
|
if (restrictedElements.length > 0) {
|
|
|
|
var rElements = restrictedElements;
|
|
|
|
restrictedElements = [];
|
|
|
|
rElements.forEach(function(video) {
|
|
|
|
video.load();
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
var u = unblock;
|
|
|
|
unblock = [];
|
|
|
|
u.forEach(function(callback) { callback(); });
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
while (queue.length < queueSize) {
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.load();
|
|
|
|
queue.push(video);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requiresUserGesture) {
|
|
|
|
window.addEventListener('keydown', removeBehaviorsRestrictions);
|
|
|
|
window.addEventListener('mousedown', removeBehaviorsRestrictions);
|
|
|
|
window.addEventListener('touchstart', removeBehaviorsRestrictions);
|
|
|
|
}
|
|
|
|
})();
|