From 71ef581b80ebafbbd9b46ce1240426dc6d46c3b7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 12 Feb 2014 09:11:59 +0000 Subject: [PATCH] improve function name, fix autoplay --- source/Ox.UI/js/Video/VideoElement.js | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/source/Ox.UI/js/Video/VideoElement.js b/source/Ox.UI/js/Video/VideoElement.js index 0aa94003..55646cf0 100644 --- a/source/Ox.UI/js/Video/VideoElement.js +++ b/source/Ox.UI/js/Video/VideoElement.js @@ -107,7 +107,7 @@ Ox.VideoElement = function(options, self) { loadItems(function() { setCurrentItem(0); - self.options.autoplay && play(); + self.options.autoplay && that.play(); }); function getCurrentTime() { @@ -160,6 +160,20 @@ Ox.VideoElement = function(options, self) { .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) { var currentTime = 0, items = self.options.items.map(function(item) { @@ -220,20 +234,6 @@ Ox.VideoElement = function(options, self) { 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) { Ox.Log('Video', 'sCI', item, self.numberOfItems); var interval; @@ -296,7 +296,7 @@ Ox.VideoElement = function(options, self) { self.$video.css(css); Ox.Log('Video', 'sCV', self.video.src, item['in'], self.video.currentTime, self.video.seeking); - onLoadedMetadata(self.$video, function(video) { + isReady(self.$video, function(video) { self.$video.one('seeked', function() { self.loading = false; !self.paused && self.video.play(); @@ -314,7 +314,7 @@ Ox.VideoElement = function(options, self) { function setCurrentItemTime(currentTime) { Ox.Log('Video', 'sCIT', 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.seeking) { self.$video.one('seeked', function() {