handle video formats and resolutions

This commit is contained in:
rlx 2011-08-19 14:44:03 +00:00
parent c5bde89971
commit ba96bfb76c
5 changed files with 45 additions and 16 deletions

View file

@ -271,7 +271,6 @@ Ox.load.UI = function(options, callback) {
Ox.UI.getImageName = function(url) { Ox.UI.getImageName = function(url) {
return imageNames[url]; return imageNames[url];
}; };
Ox.UI.getImageURL = function(name, theme) { Ox.UI.getImageURL = function(name, theme) {
theme = theme || Ox.Theme(); theme = theme || Ox.Theme();
// fixme: not the best idea to do this here // fixme: not the best idea to do this here
@ -280,6 +279,35 @@ Ox.load.UI = function(options, callback) {
} }
return imageURLs[theme + '/' + name]; return imageURLs[theme + '/' + name];
}; };
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;
}
}
});
return format;
},
Ox.UI.hideLoadingScreen = function() { Ox.UI.hideLoadingScreen = function() {
//Ox.print('hideLoadingScreen') //Ox.print('hideLoadingScreen')
var $div = $('.OxLoadingScreen'), var $div = $('.OxLoadingScreen'),

View file

@ -31,8 +31,7 @@ Ox.VideoEditor = function(options, self) {
showAnnotations: false, showAnnotations: false,
showLargeTimeline: true, showLargeTimeline: true,
subtitles: [], subtitles: [],
videoHeight: 0, videoRatio: 16/9,
videoWidth: 0,
videoSize: 'small', videoSize: 'small',
video: '', video: '',
width: 0 width: 0
@ -140,7 +139,6 @@ Ox.VideoEditor = function(options, self) {
$timeline: [], $timeline: [],
controlsHeight: 16, controlsHeight: 16,
margin: 8, margin: 8,
videoRatio: self.options.videoWidth / self.options.videoHeight
}); });
self.words = []; self.words = [];
@ -772,7 +770,7 @@ Ox.VideoEditor = function(options, self) {
left: (i + 0.5) * self.margin + width, left: (i + 0.5) * self.margin + width,
top: self.margin / 2, top: self.margin / 2,
width: widths[i], width: widths[i],
height: Math.round(widths[1] / self.videoRatio) height: Math.round(widths[1] / self.options.videoRatio)
}; };
width += widths[i]; width += widths[i];
}); });
@ -780,15 +778,15 @@ Ox.VideoEditor = function(options, self) {
size.player[0] = { size.player[0] = {
left: self.margin / 2, left: self.margin / 2,
top: self.margin / 2, top: self.margin / 2,
width: Math.round((contentWidth - 3 * self.margin + (self.controlsHeight + self.margin) / 2 * self.videoRatio) * 2/3), width: Math.round((contentWidth - 3 * self.margin + (self.controlsHeight + self.margin) / 2 * self.options.videoRatio) * 2/3),
}; };
size.player[0].height = Math.round(size.player[0].width / self.videoRatio); size.player[0].height = Math.round(size.player[0].width / self.options.videoRatio);
size.player[1] = { size.player[1] = {
left: size.player[0].left + size.player[0].width + self.margin, left: size.player[0].left + size.player[0].width + self.margin,
top: size.player[0].top, top: size.player[0].top,
width: contentWidth - 3 * self.margin - size.player[0].width width: contentWidth - 3 * self.margin - size.player[0].width
}; };
size.player[1].height = Math.ceil(size.player[1].width / self.videoRatio); size.player[1].height = Math.ceil(size.player[1].width / self.options.videoRatio);
size.player[2] = { size.player[2] = {
left: size.player[1].left, left: size.player[1].left,
top: size.player[0].top + size.player[1].height + self.controlsHeight + self.margin, top: size.player[0].top + size.player[1].height + self.controlsHeight + self.margin,

View file

@ -39,6 +39,8 @@ Ox.VideoElement = function(options, self) {
setCurrentPart(self.currentPart + 1); setCurrentPart(self.currentPart + 1);
self.video.play(); self.video.play();
} else { } else {
self.ended = true;
self.paused = true;
that.triggerEvent('ended'); that.triggerEvent('ended');
} }
}, },
@ -89,7 +91,6 @@ Ox.VideoElement = function(options, self) {
} }
function setCurrentPart(part) { function setCurrentPart(part) {
Ox.print('sCP', part)
var css = {}; var css = {};
['left', 'top', 'width', 'height'].forEach(function(key) { ['left', 'top', 'width', 'height'].forEach(function(key) {
css[key] = self.$video.css(key); css[key] = self.$video.css(key);
@ -130,6 +131,7 @@ Ox.VideoElement = function(options, self) {
that.currentTime = function() { that.currentTime = function() {
var ret; var ret;
self.ended = false;
if (arguments.length == 0) { if (arguments.length == 0) {
ret = getCurrentTime(); ret = getCurrentTime();
} else { } else {
@ -159,6 +161,10 @@ Ox.VideoElement = function(options, self) {
}; };
that.play = function() { that.play = function() {
if (self.ended) {
that.currentTime(0);
self.ended = false;
}
self.paused = false; self.paused = false;
self.video.play(); self.video.play();
return that; return that;

View file

@ -29,8 +29,6 @@ Ox.VideoPanelPlayer = function(options, self) {
showControls: true, showControls: true,
subtitles: [], subtitles: [],
video: '', video: '',
videoHeight: 0,
videoWidth: 0,
volume: 1, volume: 1,
width: 0 width: 0
}) })

View file

@ -124,6 +124,8 @@ Ox.VideoPlayer = function(options, self) {
.options(options || {}) .options(options || {})
.addClass('OxVideoPlayer'); .addClass('OxVideoPlayer');
Ox.print('VIDEO PLAYER OPTIONS', self.options)
Ox.UI.$window.bind({ Ox.UI.$window.bind({
resize: function() { resize: function() {
self.options.fullscreen && setSizes(); self.options.fullscreen && setSizes();
@ -133,14 +135,11 @@ Ox.VideoPlayer = function(options, self) {
if (Ox.isString(self.options.video)) { if (Ox.isString(self.options.video)) {
self.video = self.options.video; self.video = self.options.video;
} else { } else {
/*
self.resolutions = Ox.sort(Object.keys(self.options.video)); self.resolutions = Ox.sort(Object.keys(self.options.video));
if (!(self.options.resolution in self.options.video)) { if (!(self.options.resolution in self.options.video)) {
self.options.resolution = self.resolutions[0]; self.options.resolution = self.resolutions[0];
} }
self.video = self.options.video[self.options.resolution]; self.video = self.options.video[self.options.resolution];
*/
self.video = self.options.video(self.options.resolution, self.options.format)
} }
if (self.options.playInToOut) { if (self.options.playInToOut) {
@ -238,12 +237,12 @@ Ox.VideoPlayer = function(options, self) {
mouseenter: function() { mouseenter: function() {
showControls(); showControls();
self.mouseHasLeft = false; self.mouseHasLeft = false;
Ox.print('MOUSE HAS ENTERED') //Ox.print('MOUSE HAS ENTERED')
}, },
mouseleave: function() { mouseleave: function() {
hideControls(); hideControls();
self.mouseHasLeft = true; self.mouseHasLeft = true;
Ox.print('MOUSE HAS LEFT') //Ox.print('MOUSE HAS LEFT')
} }
}); });
} }