add Ox.getVideoInfo, move Ox.UI.getVideoFormat to Ox.getVideoFormat
This commit is contained in:
parent
807844c836
commit
708aff64e4
2 changed files with 61 additions and 34 deletions
|
@ -371,40 +371,6 @@ Ox.load.UI = function(options, callback) {
|
|||
}
|
||||
});
|
||||
/*@
|
||||
Ox.UI.getVideoFormat <f> Get supported video formats
|
||||
(formats) -> <a> of supported formats
|
||||
formats <a> list of available formats
|
||||
@*/
|
||||
Ox.UI.getVideoFormat = function(formats) {
|
||||
var aliases = {
|
||||
'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"'
|
||||
},
|
||||
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', ''))) {
|
||||
// disable WebM on Safari/Perian, seeking does not work
|
||||
if (!(
|
||||
alias == 'webm' && /safari/.test(userAgent)
|
||||
&& !/chrome/.test(userAgent) && !/linux/.test(userAgent)
|
||||
)) {
|
||||
format = f;
|
||||
return false; // break
|
||||
}
|
||||
}
|
||||
});
|
||||
return format;
|
||||
};
|
||||
/*@
|
||||
Ox.UI.hideLoadingScreen <f> hide loading screen
|
||||
() -> <u> hide loading screen
|
||||
@*/
|
||||
|
|
61
source/Ox/js/Video.js
Normal file
61
source/Ox/js/Video.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
/*@
|
||||
Ox.getVideoFormat <f> Get supported video formats
|
||||
(formats) -> <a> of supported formats
|
||||
formats <a> list of available formats
|
||||
@*/
|
||||
Ox.getVideoFormat = function(formats) {
|
||||
var aliases = {
|
||||
'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"'
|
||||
},
|
||||
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', ''))) {
|
||||
// disable WebM on Safari/Perian, seeking does not work
|
||||
if (!(
|
||||
alias == 'webm' && /safari/.test(userAgent)
|
||||
&& !/chrome/.test(userAgent) && !/linux/.test(userAgent)
|
||||
)) {
|
||||
format = f;
|
||||
return false; // break
|
||||
}
|
||||
}
|
||||
});
|
||||
return format;
|
||||
};
|
||||
|
||||
|
||||
/*@
|
||||
Ox.getVideoInfo <f>
|
||||
url <s> video url
|
||||
callback <f> 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) {
|
||||
var info = {
|
||||
duration: this.duration,
|
||||
widht: this.videoWidth,
|
||||
height: this.videoHeight,
|
||||
};
|
||||
this.src = '';
|
||||
callback(info);
|
||||
video = null;
|
||||
});
|
||||
video.preload = 'metadata';
|
||||
video.src = url;
|
||||
}, {
|
||||
maxThreads: 4
|
||||
});
|
Loading…
Reference in a new issue