From e3d8b5d3b0be14e968ec5411d494a9a8324614ec Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 28 Jan 2014 16:27:38 +0530 Subject: [PATCH] make Ox.getVideoInfo more reliable on Chrome --- source/Ox.UI/js/Video/VideoElement.js | 1 - source/Ox/js/Video.js | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/Ox.UI/js/Video/VideoElement.js b/source/Ox.UI/js/Video/VideoElement.js index ca583d84..97f0e105 100644 --- a/source/Ox.UI/js/Video/VideoElement.js +++ b/source/Ox.UI/js/Video/VideoElement.js @@ -189,7 +189,6 @@ Ox.VideoElement = function(options, self) { i++; next() } else { - Ox.Log('VIDEO', 'getVideoInfo', item.src); Ox.getVideoInfo(item.src, function(info) { item.duration = info.duration; if (!item.out) { diff --git a/source/Ox/js/Video.js b/source/Ox/js/Video.js index b814878b..a8f2252a 100644 --- a/source/Ox/js/Video.js +++ b/source/Ox/js/Video.js @@ -41,17 +41,25 @@ Ox.getVideoInfo callback gets called with object containing duration, width, height @*/ Ox.getVideoInfo = Ox.queue(function(url, callback) { + // append video element to $body to work around a + // bug in Chrome where loadedmetadata is not fired + // reliably if video element is not in the DOM. + Ox.Log('VIDEO', 'getVideoInfo', url); var video = document.createElement('video'); video.addEventListener('loadedmetadata', function(event) { + Ox.Log('VIDEO', 'getVideoInfo done', url); var info = { duration: this.duration, widht: this.videoWidth, height: this.videoHeight, }; this.src = ''; + Ox.$(video).remove(); video = null; callback(info); }); video.preload = 'metadata'; video.src = url; + video.style.display = 'none'; + Ox.$body.append(video); }, 4);