From 564603a20ea5f9c34403701c858e5c0ba7abf5b3 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 10 Jul 2013 01:32:08 +0200 Subject: [PATCH] cleanup getVideoFormat and getVideoInfo --- source/Ox/js/Video.js | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/source/Ox/js/Video.js b/source/Ox/js/Video.js index dd1e9a72..33956165 100644 --- a/source/Ox/js/Video.js +++ b/source/Ox/js/Video.js @@ -2,46 +2,44 @@ /*@ Ox.getVideoFormat Get supported video formats - (formats) -> of supported formats - formats list of available formats + (formats) -> List of supported formats + formats List of potential formats @*/ Ox.getVideoFormat = function(formats) { var aliases = { - 'mp4': 'h264', - 'm4v': 'h264', - 'ogv': 'ogg' + mp4: 'h264', + m4v: 'h264', + ogv: 'ogg' }, - format, tests = { - 'h264': 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', - 'ogg': 'video/ogg; codecs="theora, vorbis"', - 'webm': 'video/webm; codecs="vp8, vorbis"' + h264: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', + ogg: 'video/ogg; codecs="theora, vorbis"', + webm: 'video/webm; codecs="vp8, vorbis"' }, userAgent = navigator.userAgent.toLowerCase(), - video = document.createElement('video'); - Ox.forEach(formats, function(f) { - var alias = aliases[f] || f; - if (!!(video.canPlayType && video.canPlayType(tests[alias]).replace('no', ''))) { + video = document.createElement('video'), + videoFormat; + Ox.forEach(formats, function(format) { + var alias = aliases[format] || format; + if (video.canPlayType && video.canPlayType(tests[alias]).replace('no', '')) { // disable WebM on Safari/Perian, seeking does not work if (!( alias == 'webm' && /safari/.test(userAgent) && !/chrome/.test(userAgent) && !/linux/.test(userAgent) )) { - format = f; + videoFormat = format; return false; // break } } }); - return format; + return videoFormat; }; - /*@ Ox.getVideoInfo url video url callback gets called with object containing duration, width, height @*/ - Ox.getVideoInfo = Ox.queue(function(url, callback) { var video = document.createElement('video'); video.addEventListener('loadedmetadata', function(event) { @@ -51,11 +49,9 @@ Ox.getVideoInfo = Ox.queue(function(url, callback) { height: this.videoHeight, }; this.src = ''; - callback(info); video = null; + callback(info); }); video.preload = 'metadata'; video.src = url; -}, { - maxThreads: 4 -}); +}, 4);