improve function name, fix autoplay

This commit is contained in:
j 2014-02-12 09:11:59 +00:00
parent 5fae9d2213
commit 71ef581b80

View file

@ -107,7 +107,7 @@ Ox.VideoElement = function(options, self) {
loadItems(function() { loadItems(function() {
setCurrentItem(0); setCurrentItem(0);
self.options.autoplay && play(); self.options.autoplay && that.play();
}); });
function getCurrentTime() { function getCurrentTime() {
@ -160,6 +160,20 @@ Ox.VideoElement = function(options, self) {
.appendTo(that); .appendTo(that);
} }
function isReady($video, callback) {
if ($video[0].seeking) {
$video.one('seeked', function(event) {
callback($video[0]);
});
} else if ($video[0].readyState) {
callback($video[0]);
} else {
$video.one('loadedmetadata', function(event) {
callback($video[0]);
});
}
}
function loadItems(callback) { function loadItems(callback) {
var currentTime = 0, var currentTime = 0,
items = self.options.items.map(function(item) { items = self.options.items.map(function(item) {
@ -220,20 +234,6 @@ Ox.VideoElement = function(options, self) {
nextVideo.src = next.src; nextVideo.src = next.src;
} }
function onLoadedMetadata($video, callback) {
if ($video[0].seeking) {
$video.one('seeked', function(event) {
callback($video[0]);
});
} else if ($video[0].readyState) {
callback($video[0]);
} else {
$video.one('loadedmetadata', function(event) {
callback($video[0]);
});
}
}
function setCurrentItem(item) { function setCurrentItem(item) {
Ox.Log('Video', 'sCI', item, self.numberOfItems); Ox.Log('Video', 'sCI', item, self.numberOfItems);
var interval; var interval;
@ -296,7 +296,7 @@ Ox.VideoElement = function(options, self) {
self.$video.css(css); self.$video.css(css);
Ox.Log('Video', 'sCV', self.video.src, item['in'], Ox.Log('Video', 'sCV', self.video.src, item['in'],
self.video.currentTime, self.video.seeking); self.video.currentTime, self.video.seeking);
onLoadedMetadata(self.$video, function(video) { isReady(self.$video, function(video) {
self.$video.one('seeked', function() { self.$video.one('seeked', function() {
self.loading = false; self.loading = false;
!self.paused && self.video.play(); !self.paused && self.video.play();
@ -314,7 +314,7 @@ Ox.VideoElement = function(options, self) {
function setCurrentItemTime(currentTime) { function setCurrentItemTime(currentTime) {
Ox.Log('Video', 'sCIT', currentTime, self.video.currentTime, Ox.Log('Video', 'sCIT', currentTime, self.video.currentTime,
'delta', currentTime - self.video.currentTime); 'delta', currentTime - self.video.currentTime);
onLoadedMetadata(self.$video, function(video) { isReady(self.$video, function(video) {
if (self.video == video) { if (self.video == video) {
if(self.seeking) { if(self.seeking) {
self.$video.one('seeked', function() { self.$video.one('seeked', function() {