2011-05-12 22:12:41 +00:00
|
|
|
/*@
|
2011-05-13 15:44:50 +00:00
|
|
|
Ox.VideoPlayer <f> Generic Video Player
|
2011-05-12 22:12:41 +00:00
|
|
|
(options, self) -> <o> Video Player
|
|
|
|
options <o> Options
|
2011-05-13 15:44:50 +00:00
|
|
|
annotation <[o]> Array of annotation tracks
|
|
|
|
name <s> Name of the annotation track
|
|
|
|
data <[o]> Annotation data
|
|
|
|
in <n> In point (sec)
|
|
|
|
out <n> Out point (sec)
|
|
|
|
text <s> Text
|
|
|
|
controls <[s]> Controls, from left to right
|
|
|
|
Can be 'play', 'playInToOut', 'mute', 'volume', 'size', 'scale',
|
|
|
|
'timeline', 'space', 'position', 'settings'. The 'space' control
|
|
|
|
is just empty space that separates left-aligned from right-aligned
|
|
|
|
controls
|
|
|
|
duration <n|-1> Duration (sec)
|
|
|
|
enableKeyboard <b|false> If true, enable keyboard controls
|
|
|
|
externalControls <b|false> If true, controls are outside the video
|
|
|
|
focus <s|'click'> focus on 'click', 'load' or 'mouseover'
|
|
|
|
fps <n|25> Frames per second
|
2011-05-15 07:26:00 +00:00
|
|
|
fullscreen <b|false> If true, video is in fullscreen
|
2011-05-13 15:44:50 +00:00
|
|
|
height <n|144> Height in px (excluding external controls)
|
|
|
|
in <n> In point (sec)
|
|
|
|
keepIconVisible <b|false> If true, play icon stays visible after mouseleave
|
|
|
|
keepLargeTimelineVisible <b|false> If true, large timeline stays visible after mouseleave
|
|
|
|
keepLogoVisible <b|false> If true, logo stays visible after mouseleave
|
|
|
|
logo <s|''> Logo image URL
|
|
|
|
logoLink <s|''> Logo link URL
|
|
|
|
logoTitle <s|''> Text for tooltip
|
|
|
|
muted <b|false> If true, video is muted
|
|
|
|
paused <b|false> If true, video is paused
|
|
|
|
playInToOut <b|false> If true, video plays only from in to out
|
|
|
|
position <n|0> Initial position (sec)
|
|
|
|
poster <s|''> Poster URL
|
|
|
|
posterFrame <n|-1> Position of poster frame (sec)
|
|
|
|
preload <s|'auto'> 'auto', 'metadata' or 'none'
|
|
|
|
out <n|-1> Out point (sec)
|
|
|
|
scaleToFill <b|false> If true, scale to fill (otherwise, scale to fit)
|
|
|
|
showFind <b|false> If true, show find input
|
|
|
|
showHours <b|false> If true, don't show hours for videos shorter than one hour
|
|
|
|
showIcon <b|false> If true, show play icon
|
|
|
|
showIconOnLoad <b|false> If true, show icon on load
|
2011-05-14 19:32:49 +00:00
|
|
|
showInterfaceOnLoad <b|false> If true, show controls and title on load
|
2011-05-13 15:44:50 +00:00
|
|
|
showLargeTimeline <b|false> If true, show large timeline
|
2011-05-14 19:32:49 +00:00
|
|
|
showMilliseconds <n|0> Number of decimals to show
|
2011-05-13 15:44:50 +00:00
|
|
|
showPointMarkers <b|false> If true, show in/out markers
|
2011-05-14 19:32:49 +00:00
|
|
|
showProgress <|false> If true, show buffering progress
|
2011-05-13 15:44:50 +00:00
|
|
|
sizeIsLarge <b|false> If true, initial state of the size control is large
|
|
|
|
subtitles <s|[o]|[]> URL or SRT or array of subtitles
|
|
|
|
in <n> In point (sec)
|
|
|
|
out <n> Out point (sec)
|
2011-05-12 22:12:41 +00:00
|
|
|
text <s> Text
|
2011-05-13 15:44:50 +00:00
|
|
|
timeline <s> Timeline image URL
|
|
|
|
title <s|''> Video title
|
|
|
|
type <s|'play'> 'play', 'in' or 'out'
|
|
|
|
video <s|''> Video URL
|
|
|
|
volume <n|1> Volume (0-1)
|
|
|
|
width <n|256> Width in px
|
2011-05-12 22:12:41 +00:00
|
|
|
@*/
|
|
|
|
|
2011-05-12 10:39:48 +00:00
|
|
|
Ox.VideoPlayer = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
2011-05-13 15:44:50 +00:00
|
|
|
annotations: [],
|
|
|
|
controls: [],
|
2011-05-14 19:32:49 +00:00
|
|
|
duration: 86399,
|
2011-05-13 15:44:50 +00:00
|
|
|
enableKeyboard: false,
|
|
|
|
externalControls: false,
|
|
|
|
focus: 'click',
|
|
|
|
fps: 25,
|
2011-05-15 07:26:00 +00:00
|
|
|
fullscreen: false,
|
2011-05-13 15:44:50 +00:00
|
|
|
height: 144,
|
2011-05-14 19:32:49 +00:00
|
|
|
'in': 0,
|
2011-05-13 15:44:50 +00:00
|
|
|
keepIconVisible: false,
|
|
|
|
keepLargeTimelineVisible: false,
|
|
|
|
keepLogoVisible: false,
|
|
|
|
logo: '',
|
2011-05-12 22:12:41 +00:00
|
|
|
logoLink: '',
|
|
|
|
logoTitle: '',
|
2011-05-13 15:44:50 +00:00
|
|
|
muted: false,
|
|
|
|
paused: false,
|
|
|
|
playInToOut: false,
|
2011-05-12 10:39:48 +00:00
|
|
|
position: 0,
|
2011-05-13 15:44:50 +00:00
|
|
|
poster: '',
|
|
|
|
preload: 'auto',
|
2011-05-14 19:32:49 +00:00
|
|
|
out: 0,
|
2011-05-13 15:44:50 +00:00
|
|
|
scaleToFill: false,
|
|
|
|
showFind: false,
|
|
|
|
showHours: false,
|
|
|
|
showIcon: false,
|
|
|
|
showIconOnLoad: false,
|
2011-05-14 19:32:49 +00:00
|
|
|
showInterfaceOnLoad: false,
|
2011-05-13 15:44:50 +00:00
|
|
|
showLargeTimeline: false,
|
2011-05-14 19:32:49 +00:00
|
|
|
showMilliseconds: 0,
|
2011-05-13 15:44:50 +00:00
|
|
|
showPointMarkers: false,
|
2011-05-14 19:32:49 +00:00
|
|
|
showProgress: false,
|
2011-05-12 22:12:41 +00:00
|
|
|
subtitles: [],
|
2011-05-13 15:44:50 +00:00
|
|
|
timeline: '',
|
2011-05-12 22:12:41 +00:00
|
|
|
title: '',
|
2011-05-13 15:44:50 +00:00
|
|
|
type: 'play',
|
|
|
|
video: '',
|
|
|
|
volume: 1,
|
2011-05-12 10:39:48 +00:00
|
|
|
width: 256
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2011-05-14 19:32:49 +00:00
|
|
|
.addClass('OxVideo')
|
2011-05-12 10:39:48 +00:00
|
|
|
.css({
|
2011-05-13 15:44:50 +00:00
|
|
|
position: 'absolute'
|
2011-05-12 10:39:48 +00:00
|
|
|
});
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
Ox.UI.$window.bind({
|
|
|
|
resize: function() {
|
|
|
|
self.options.fullscreen && setSizes();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self['in'] = self.options.playInToOut ? self.options['in'] : 0,
|
|
|
|
self.out = self.options.playInToOut ? self.options.out : self.options.duration;
|
|
|
|
self.options.duration = self.out - self['in'];
|
|
|
|
self.options.position = Ox.limit(self.options.position, self['in'], self.out);
|
|
|
|
Ox.print('p/d', self.options.position, self.options.duration);
|
|
|
|
// fixme: this is _relative_, resizing can happen
|
|
|
|
self.millisecondsPerFrame = 1000 / self.options.fps;
|
|
|
|
self.secondsPerFrame = 1 / self.options.fps;
|
|
|
|
self.barHeight = 16;
|
2011-05-15 07:26:00 +00:00
|
|
|
self.width = self.options.fullscreen ? window.innerWidth : self.options.width;
|
|
|
|
self.height = self.options.fullscreen ? window.innerHeight : self.options.height;
|
2011-05-14 19:32:49 +00:00
|
|
|
|
|
|
|
if (self.options.enableKeyboard) {
|
|
|
|
that.bindEvent({
|
|
|
|
key_left: function() {
|
2011-05-15 07:26:00 +00:00
|
|
|
setPosition(self.options.position - self.secondsPerFrame);
|
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-14 19:32:49 +00:00
|
|
|
},
|
|
|
|
key_right: function() {
|
2011-05-15 07:26:00 +00:00
|
|
|
setPosition(self.options.position + self.secondsPerFrame);
|
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-14 19:32:49 +00:00
|
|
|
},
|
2011-05-15 07:52:37 +00:00
|
|
|
key_shift_f: function() {
|
|
|
|
toggleFullscreen();
|
|
|
|
},
|
2011-05-14 19:32:49 +00:00
|
|
|
key_space: function() {
|
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
|
|
|
togglePaused();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.options.enableKeyboard) {
|
|
|
|
if (self.options.focus == 'mouseenter') {
|
|
|
|
that.bind({
|
|
|
|
mouseenter: that.gainFocus,
|
|
|
|
mouseleave: that.loseFocus
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
that.bind({
|
|
|
|
click: that.gainFocus
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!self.options.externalControls && self.options.controls.length) || self.options.showIcon || self.options.title) {
|
2011-05-13 15:44:50 +00:00
|
|
|
that.bind({
|
|
|
|
mouseenter: showInterface,
|
|
|
|
mouseleave: hideInterface
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-12 22:12:41 +00:00
|
|
|
if (Ox.isString(self.options.subtitles)) {
|
|
|
|
if (self.options.subtitles.indexOf('\n') > -1) {
|
|
|
|
self.options.subtitles = Ox.parseSRT(self.options.subtitles);
|
|
|
|
} else {
|
|
|
|
Ox.get(self.options.subtitles, function(data) {
|
|
|
|
self.options.subtitles = Ox.parseSRT(data);
|
|
|
|
});
|
|
|
|
//self.options.subtitles = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-12 10:39:48 +00:00
|
|
|
self.buffered = [];
|
|
|
|
self.controlsTimeout;
|
2011-05-12 11:15:32 +00:00
|
|
|
self.dragTimeout;
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
self.$videoContainer = $('<div>')
|
2011-05-12 10:39:48 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-14 19:32:49 +00:00
|
|
|
background: 'rgb(0, 0, 0)',
|
2011-05-13 15:44:50 +00:00
|
|
|
overflow: 'hidden'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.bind({
|
|
|
|
click: function() {
|
|
|
|
togglePaused();
|
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
|
|
|
}
|
|
|
|
})
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(that.$element)
|
|
|
|
|
|
|
|
self.$video = $('<video>')
|
|
|
|
.attr(Ox.extend({
|
|
|
|
preload: self.options.preload,
|
|
|
|
src: self.options.video
|
|
|
|
}, !self.options.paused ? {
|
|
|
|
autoplay: 'autoplay'
|
2011-05-14 19:32:49 +00:00
|
|
|
} : {}/*, self.options.poster ? {
|
2011-05-13 15:44:50 +00:00
|
|
|
poster: self.options.poster
|
2011-05-14 19:32:49 +00:00
|
|
|
} : {}*/))
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute'
|
2011-05-12 10:39:48 +00:00
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.bind(Ox.extend({
|
2011-05-13 15:44:50 +00:00
|
|
|
ended: ended,
|
2011-05-12 10:39:48 +00:00
|
|
|
loadedmetadata: loadedmetadata,
|
2011-05-13 15:44:50 +00:00
|
|
|
seeked: seeked,
|
|
|
|
seeking: seeking
|
2011-05-14 19:32:49 +00:00
|
|
|
}, self.options.progress ? {
|
|
|
|
progress: progress
|
|
|
|
} : {}))
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
|
|
|
self.video = self.$video[0];
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.poster) {
|
|
|
|
self.$poster = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: self.options.poster
|
2011-05-12 20:02:22 +00:00
|
|
|
})
|
|
|
|
.css({
|
2011-05-14 19:32:49 +00:00
|
|
|
position: 'absolute'
|
2011-05-12 20:02:22 +00:00
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
|
|
|
self.posterIsVisible = true;
|
2011-05-12 20:02:22 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
if (self.options.logo) {
|
|
|
|
self.$logo = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: self.options.logo
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
cursor: self.options.logoLink ? 'pointer' : 'default',
|
|
|
|
opacity: 0.25,
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
2011-05-13 15:44:50 +00:00
|
|
|
if (self.options.logoTitle) {
|
|
|
|
self.$logoTooltip = Ox.Tooltip({
|
|
|
|
title: self.options.logoTitle
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:51:17 +00:00
|
|
|
self.$loadingIcon = $('<img>')
|
|
|
|
.attr({
|
2011-05-14 19:32:49 +00:00
|
|
|
src: Ox.UI.getImagePath('symbolLoadingAnimated.svg')
|
|
|
|
.replace('/classic/', '/modern/')
|
2011-05-12 10:51:17 +00:00
|
|
|
})
|
|
|
|
.css({
|
2011-05-14 19:32:49 +00:00
|
|
|
position: 'absolute'
|
2011-05-12 10:51:17 +00:00
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
2011-05-12 10:51:17 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.showIcon || self.options.showIconOnLoad) {
|
|
|
|
self.$playIcon = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: Ox.UI.getImagePath(
|
|
|
|
'symbol' + (self.options.paused ? 'Play' : 'Pause') + '.svg'
|
|
|
|
).replace('/classic/', '/modern/')
|
|
|
|
})
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
border: '2px solid rgb(255, 255, 255)',
|
2011-05-14 19:32:49 +00:00
|
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
2011-05-13 15:44:50 +00:00
|
|
|
opacity: 0
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
2011-05-15 07:26:00 +00:00
|
|
|
if (self.options.showIcon) {
|
|
|
|
self.$playIcon.addClass('OxInterface');
|
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.showIconOnLoad) {
|
|
|
|
self.iconIsVisible = true;
|
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
2011-05-12 22:12:41 +00:00
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
if (self.options.subtitles.length) {
|
|
|
|
self.$subtitle = $('<div>')
|
|
|
|
//.addClass('OxSubtitle')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
textAlign: 'center',
|
|
|
|
textShadow: 'rgba(0, 0, 0, 1) 0 0 4px',
|
|
|
|
color: 'rgb(255, 255, 255)'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$videoContainer);
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
2011-05-12 22:12:41 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.title) {
|
|
|
|
self.$titlebar = $('<div>')
|
2011-05-13 15:44:50 +00:00
|
|
|
.addClass('OxInterface')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-05-14 19:32:49 +00:00
|
|
|
height: (self.barHeight - 1) + 'px',
|
|
|
|
paddingTop: '1px',
|
|
|
|
textAlign: 'center',
|
|
|
|
color: 'rgb(255, 255, 255)',
|
|
|
|
opacity: 0
|
2011-05-13 15:44:50 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
backgroundImage: '-moz-linear-gradient(top, rgba(64, 64, 64, 0.5), rgba(0, 0, 0, 0.5))'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
backgroundImage: '-webkit-linear-gradient(top, rgba(64, 64, 64, 0.5), rgba(0, 0, 0, 0.5))'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.html(self.options.title)
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(that.$element);
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.controls.length) {
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$controls = Ox.Bar({
|
|
|
|
size: self.barHeight
|
|
|
|
})
|
|
|
|
.addClass('OxInterface')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: 0,
|
|
|
|
opacity: self.options.externalControls ? 1 : 0
|
|
|
|
})
|
|
|
|
.appendTo(that.$element);
|
|
|
|
|
|
|
|
if (!self.options.externalControls) {
|
|
|
|
self.$controls.css({
|
|
|
|
backgroundImage: '-moz-linear-gradient(top, rgba(64, 64, 64, 0.5), rgba(0, 0, 0, 0.5))'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
backgroundImage: '-webkit-linear-gradient(top, rgba(64, 64, 64, 0.5), rgba(0, 0, 0, 0.5))'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.$control = {};
|
2011-05-13 15:44:50 +00:00
|
|
|
|
|
|
|
self.options.controls.forEach(function(control) {
|
|
|
|
|
|
|
|
if (control == 'play') {
|
|
|
|
|
|
|
|
self.$playButton = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
// FIXME: this is retarded, fix Ox.Button
|
|
|
|
title: [
|
|
|
|
{id: 'play', title: 'play', selected: self.options.paused},
|
|
|
|
{id: 'pause', title: 'pause', selected: !self.options.paused}
|
|
|
|
],
|
|
|
|
tooltip: ['Play', 'Pause'],
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
|
|
|
.bindEvent('click', togglePaused)
|
|
|
|
.appendTo(self.$controls);
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
} else if (control == 'playInToOut') {
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
self.$playInToOutButton = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
title: 'playInToOut',
|
|
|
|
tooltip: 'Play In to Out',
|
|
|
|
type: 'image'
|
2011-05-12 20:02:22 +00:00
|
|
|
})
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({float: 'left'})
|
|
|
|
.bindEvent('click', playInToOut)
|
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
|
|
|
} else if (control == 'mute') {
|
|
|
|
|
|
|
|
self.$muteButton = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
title: [
|
2011-05-14 19:32:49 +00:00
|
|
|
{id: 'mute', title: 'mute', selected: !self.options.muted},
|
|
|
|
{id: 'unmute', title: 'unmute', selected: self.options.muted}
|
2011-05-13 15:44:50 +00:00
|
|
|
],
|
|
|
|
tooltip: ['Mute', 'Unmute'],
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
|
|
|
.bindEvent('click', toggleMuted)
|
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
|
|
|
} else if (control == 'volume') {
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
} else if (control == 'scale') {
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$scaleButton = Ox.Button({
|
2011-05-13 15:44:50 +00:00
|
|
|
style: 'symbol',
|
|
|
|
title: [
|
2011-05-15 07:26:00 +00:00
|
|
|
{id: 'fill', title: 'fill', selected: !self.options.scaleToFill},
|
|
|
|
{id: 'fit', title: 'fit', selected: self.options.scaleToFill}
|
2011-05-13 15:44:50 +00:00
|
|
|
],
|
2011-05-15 07:26:00 +00:00
|
|
|
tooltip: ['Scale to Fill', 'Scale to Fit'],
|
2011-05-13 15:44:50 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
2011-05-15 07:26:00 +00:00
|
|
|
.bindEvent('click', toggleScale)
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
} else if (control == 'fullscreen') {
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$fullscreenButton = Ox.Button({
|
2011-05-13 15:44:50 +00:00
|
|
|
style: 'symbol',
|
|
|
|
title: [
|
2011-05-15 07:26:00 +00:00
|
|
|
{id: 'grow', title: 'grow', selected: !self.options.fullscreen},
|
|
|
|
{id: 'shrink', title: 'shrink', selected: self.options.fullscreen}
|
2011-05-13 15:44:50 +00:00
|
|
|
],
|
2011-05-15 07:26:00 +00:00
|
|
|
tooltip: ['Enter Fullscreen', 'Exit Fullscreen'],
|
2011-05-13 15:44:50 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
2011-05-15 07:26:00 +00:00
|
|
|
.bindEvent('click', toggleFullscreen)
|
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
|
|
|
} else if (control == 'size') {
|
|
|
|
|
|
|
|
self.$sizeButton = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
title: [
|
|
|
|
{id: 'grow', title: 'grow', selected: !self.options.sizeIsLarge},
|
|
|
|
{id: 'shrink', title: 'shrink', selected: self.options.sizeIsLarge}
|
|
|
|
],
|
|
|
|
tooltip: ['Larger', 'Smaller'],
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
|
|
|
.bindEvent('click', toggleSize)
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
}else if (control == 'timeline') {
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$timeline = Ox.Element()
|
|
|
|
.addClass('timeline')
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
height: self.barHeight + 'px',
|
|
|
|
background: 'rgba(0, 0, 0, 0.75)',
|
|
|
|
borderRadius: self.barHeight / 2 + 'px'
|
|
|
|
})
|
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$timelineImages = Ox.Element()
|
|
|
|
.addClass('timelineimages')
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
height: self.barHeight + 'px',
|
|
|
|
marginLeft: self.barHeight / 2 + 'px'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$timeline);
|
2011-05-12 11:15:32 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$timelineImage = $('<img>')
|
|
|
|
.addClass('timelineimage')
|
2011-05-13 15:44:50 +00:00
|
|
|
.attr({
|
|
|
|
src: self.options.timeline
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
height: self.barHeight + 'px'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$timelineImages.$element);
|
|
|
|
|
|
|
|
///*
|
|
|
|
if (self.options.showProgress) {
|
|
|
|
self.$progress = $('<img>')
|
|
|
|
.attr({
|
|
|
|
src: getProgressImageURL()
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
height: self.barHeight + 'px',
|
|
|
|
})
|
|
|
|
.appendTo(self.$timelineImages.$element);
|
|
|
|
}
|
|
|
|
//*/
|
2011-05-13 15:44:50 +00:00
|
|
|
|
|
|
|
self.$positionMarker = $('<div>')
|
2011-05-14 19:32:49 +00:00
|
|
|
.addClass('positionmarker')
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
width: '14px',
|
|
|
|
height: '14px',
|
|
|
|
border: '1px solid rgba(0, 0, 0, 0.5)',
|
|
|
|
borderRadius: '8px'
|
|
|
|
})
|
|
|
|
.append(
|
|
|
|
self.$positionMarkerRing = $('<div>')
|
|
|
|
.css({
|
|
|
|
width: '10px',
|
|
|
|
height: '10px',
|
|
|
|
border: '2px solid rgba(255, 255, 255, 0.5)',
|
|
|
|
borderRadius: '7px',
|
|
|
|
})
|
|
|
|
.append(
|
|
|
|
$('<div>')
|
|
|
|
.css({
|
|
|
|
width: '8px',
|
|
|
|
height: '8px',
|
|
|
|
border: '1px solid rgba(0, 0, 0, 0.5)',
|
|
|
|
borderRadius: '5px',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$timeline.$element);
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$timelineInterface = Ox.Element()
|
2011-05-13 15:44:50 +00:00
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
height: self.barHeight + 'px',
|
2011-05-12 20:02:22 +00:00
|
|
|
})
|
2011-05-13 15:44:50 +00:00
|
|
|
.appendTo(self.$controls);
|
|
|
|
|
|
|
|
self.$tooltip = Ox.Tooltip({
|
|
|
|
animate: false
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (control == 'space') {
|
2011-05-14 19:32:49 +00:00
|
|
|
|
|
|
|
self.$space = $('<div>')
|
|
|
|
.css({float: 'left'})
|
|
|
|
.html(' ') // fixme: ??
|
|
|
|
.appendTo(self.$controls.$element);
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
} else if (control == 'position') {
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.positionWidth = 48 +
|
|
|
|
!!self.options.showMilliseconds * 2
|
|
|
|
+ self.options.showMilliseconds * 6;
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
self.$position = $('<div>')
|
|
|
|
.addClass('foo')
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
2011-05-14 19:32:49 +00:00
|
|
|
width: (self.positionWidth - 4) + 'px',
|
2011-05-13 15:44:50 +00:00
|
|
|
height: '12px',
|
|
|
|
padding: '2px',
|
|
|
|
fontSize: '9px',
|
2011-05-14 19:32:49 +00:00
|
|
|
textAlign: 'center',
|
|
|
|
color: 'rgb(255, 255, 255)'
|
2011-05-13 15:44:50 +00:00
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.html(formatPosition)
|
2011-05-13 15:44:50 +00:00
|
|
|
.bind({
|
|
|
|
click: function() {
|
|
|
|
if (!self.options.paused) {
|
|
|
|
self.wasPlaying = true;
|
|
|
|
togglePaused();
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
self.$position.hide();
|
|
|
|
self.$positionInput
|
|
|
|
.options({
|
2011-05-14 19:32:49 +00:00
|
|
|
value: formatPosition()
|
2011-05-13 15:44:50 +00:00
|
|
|
})
|
|
|
|
.show()
|
|
|
|
.focusInput(false);
|
|
|
|
}
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$controls.$element);
|
2011-05-13 15:44:50 +00:00
|
|
|
|
|
|
|
self.$positionInput = Ox.Input({
|
2011-05-14 19:32:49 +00:00
|
|
|
value: formatPosition(),
|
|
|
|
width: self.positionWidth
|
2011-05-13 15:44:50 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
background: 'rgba(0, 0, 0, 0)',
|
|
|
|
MozBoxShadow: '0 0 0',
|
|
|
|
WebkitBoxShadow: '0 0 0'
|
|
|
|
})
|
2011-05-14 19:32:49 +00:00
|
|
|
.bind({
|
|
|
|
blur: function() {
|
|
|
|
},
|
|
|
|
focus: function() {
|
|
|
|
}
|
|
|
|
})
|
2011-05-13 15:44:50 +00:00
|
|
|
.bindEvent({
|
2011-05-15 07:26:00 +00:00
|
|
|
focus: function() {
|
|
|
|
self.inputHasFocus = true;
|
|
|
|
},
|
|
|
|
blur: function() {
|
|
|
|
self.inputHasFocus = false;
|
|
|
|
submitPositionInput();
|
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
})
|
|
|
|
.hide()
|
2011-05-14 19:32:49 +00:00
|
|
|
.appendTo(self.$controls.$element);
|
2011-05-13 15:44:50 +00:00
|
|
|
|
|
|
|
self.$positionInput.children('input').css({
|
2011-05-14 19:32:49 +00:00
|
|
|
width: (self.positionWidth - 6) + 'px',
|
2011-05-13 15:44:50 +00:00
|
|
|
height: '16px',
|
|
|
|
padding: '0 3px 0 3px',
|
|
|
|
border: '0px',
|
|
|
|
borderRadius: '8px',
|
|
|
|
fontSize: '9px',
|
|
|
|
color: 'rgb(255, 255, 255)'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
background: '-moz-linear-gradient(top, rgba(0, 0, 0, 0.5), rgba(64, 64, 64, 0.5))'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
background: '-webkit-linear-gradient(top, rgba(0, 0, 0, 0.5), rgba(64, 64, 64, 0.5))'
|
|
|
|
});
|
|
|
|
|
2011-05-12 20:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
setSizes();
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function ended() {
|
2011-05-14 19:32:49 +00:00
|
|
|
if (!self.options.paused) {
|
|
|
|
togglePaused();
|
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
|
|
|
}
|
|
|
|
if (self.options.poster) {
|
|
|
|
self.$poster.animate({
|
|
|
|
opacity: 1
|
|
|
|
}, 250);
|
|
|
|
self.posterIsVisible = true;
|
|
|
|
}
|
|
|
|
if (self.options.showIconOnLoad) {
|
|
|
|
self.$playIcon.animate({
|
|
|
|
opacity: 1
|
|
|
|
}, 250);
|
|
|
|
self.iconIsVisible = true;
|
|
|
|
}
|
2011-05-12 20:02:22 +00:00
|
|
|
}
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
function formatPosition(position) {
|
|
|
|
position = Ox.isUndefined(position) ? self.options.position : position;
|
|
|
|
return Ox.formatDuration(position, self.options.showMilliseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition(e) {
|
|
|
|
// fixme: no offsetX in firefox???
|
|
|
|
if ($.browser.mozilla) {
|
|
|
|
//Ox.print(e, e.layerX - 56)
|
|
|
|
return Ox.limit(
|
|
|
|
(e.layerX - 48 - self.barHeight / 2) / self.timelineImageWidth * self.video.duration,
|
|
|
|
0, self.video.duration
|
|
|
|
);
|
2011-05-12 10:39:48 +00:00
|
|
|
} else {
|
2011-05-14 19:32:49 +00:00
|
|
|
/*Ox.print(e.offsetX, Ox.limit(
|
|
|
|
(e.offsetX - self.barHeight / 2) / self.timelineImageWidth * self.video.duration,
|
|
|
|
0, self.video.duration
|
|
|
|
))*/
|
|
|
|
return Ox.limit(
|
|
|
|
(e.offsetX - self.barHeight / 2) / self.timelineImageWidth * self.video.duration,
|
|
|
|
0, self.video.duration
|
|
|
|
);
|
2011-05-12 10:39:48 +00:00
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getProgressImageURL() {
|
|
|
|
Ox.print('---', self.timelineImageWidth)
|
|
|
|
if (!self.timelineImageWidth) return;
|
|
|
|
var width = self.timelineImageWidth,
|
2011-05-13 15:44:50 +00:00
|
|
|
height = self.barHeight,
|
2011-05-14 19:32:49 +00:00
|
|
|
canvas = $('<canvas>')
|
2011-05-12 10:39:48 +00:00
|
|
|
.attr({
|
|
|
|
width: width,
|
2011-05-14 19:32:49 +00:00
|
|
|
height: height
|
|
|
|
})[0],
|
|
|
|
context = canvas.getContext('2d'),
|
|
|
|
imageData, data;
|
2011-05-12 10:39:48 +00:00
|
|
|
context.fillStyle = 'rgba(255, 0, 0, 0.5)';
|
|
|
|
context.fillRect(0, 0, width, height);
|
2011-05-14 19:32:49 +00:00
|
|
|
imageData = context.getImageData(0, 0, width, height),
|
|
|
|
data = imageData.data;
|
2011-05-12 10:39:48 +00:00
|
|
|
self.buffered.forEach(function(range) {
|
2011-05-13 15:44:50 +00:00
|
|
|
var left = Math.round(range[0] * width / self.video.duration),
|
|
|
|
right = Math.round(range[1] * width / self.video.duration);
|
2011-05-12 10:39:48 +00:00
|
|
|
Ox.loop(left, right, function(x) {
|
|
|
|
Ox.loop(height, function(y) {
|
|
|
|
index = x * 4 + y * 4 * width;
|
|
|
|
data[index + 3] = 0;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
context.putImageData(imageData, 0, 0);
|
|
|
|
return canvas.toDataURL();
|
|
|
|
}
|
|
|
|
|
2011-05-12 22:12:41 +00:00
|
|
|
function getSubtitle() {
|
|
|
|
var subtitle = '';
|
|
|
|
Ox.forEach(self.options.subtitles, function(v) {
|
|
|
|
if (
|
|
|
|
v['in'] <= self.options.position &&
|
|
|
|
v.out > self.options.position
|
|
|
|
) {
|
|
|
|
subtitle = v.text;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function hideInterface() {
|
2011-05-14 19:32:49 +00:00
|
|
|
if (!self.inputHasFocus) {
|
2011-05-12 20:02:22 +00:00
|
|
|
self.controlsTimeout = setTimeout(function() {
|
2011-05-14 19:32:49 +00:00
|
|
|
that.find('.OxInterface').animate({
|
2011-05-12 20:02:22 +00:00
|
|
|
opacity: 0
|
|
|
|
}, 250);
|
2011-05-13 15:44:50 +00:00
|
|
|
self.$logo && self.$logo.animate({
|
|
|
|
top: self.logoMargin + 'px',
|
|
|
|
opacity: 0.25
|
|
|
|
}, 250, function() {
|
|
|
|
self.options.logoLink && self.$logo.unbind('click');
|
|
|
|
self.options.logoTitle &&
|
|
|
|
self.$logo.unbind('mouseenter').unbind('mouseleave');
|
|
|
|
});
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$subtitle && self.$subtitle.animate({
|
2011-05-13 15:44:50 +00:00
|
|
|
bottom: parseInt(self.options.height / 16) + 'px',
|
|
|
|
});
|
2011-05-12 20:02:22 +00:00
|
|
|
}, 1000);
|
|
|
|
}
|
2011-05-12 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function hideLoadingIcon() {
|
|
|
|
self.$loadingIcon.hide().attr({
|
|
|
|
src: Ox.UI.getImagePath('symbolLoading.svg')
|
|
|
|
.replace('/classic/', '/modern/')
|
|
|
|
});
|
2011-05-12 10:51:17 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function loadedmetadata() {
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.loaded = true;
|
|
|
|
self.out = self.options.playInToOut &&
|
|
|
|
self.options.out < self.video.duration ?
|
|
|
|
self.options.out : self.video.duration;
|
|
|
|
self.options.duration = self.out - self['in'];
|
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$video.css(getCSS('video'));
|
2011-05-15 07:52:37 +00:00
|
|
|
self.$poster && self.$poster.css(getCSS('poster'));
|
2011-05-13 15:44:50 +00:00
|
|
|
|
2011-05-12 11:15:32 +00:00
|
|
|
hideLoadingIcon();
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.showIcon || self.options.showIconOnLoad) {
|
|
|
|
//!self.options.keepIconVisible && self.$playIcon.addClass('OxInterface');
|
|
|
|
if (self.options.showIconOnLoad) {
|
|
|
|
self.$playIcon.animate({
|
|
|
|
opacity: 1
|
|
|
|
}, 250);
|
2011-05-12 11:15:32 +00:00
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (self.options.enableKeyboard && self.options.focus == 'load') {
|
|
|
|
that.gainFocus();
|
|
|
|
}
|
|
|
|
self.$timeline && self.$timelineInterface
|
2011-05-12 11:15:32 +00:00
|
|
|
.bind({
|
2011-05-12 20:02:22 +00:00
|
|
|
mousedown: mousedownTrack,
|
|
|
|
mouseleave: mouseleaveTrack,
|
|
|
|
mousemove: mousemoveTrack,
|
2011-05-12 11:15:32 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
2011-05-12 20:02:22 +00:00
|
|
|
drag: dragTrack,
|
|
|
|
dragpause: dragpauseTrack,
|
|
|
|
dragend: dragpauseTrack
|
2011-05-12 11:15:32 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:22 +00:00
|
|
|
function dragTrack(e) {
|
2011-05-12 11:15:32 +00:00
|
|
|
setPosition(getPosition(e));
|
2011-05-13 15:44:50 +00:00
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-12 11:15:32 +00:00
|
|
|
if (self.dragTimeout) {
|
|
|
|
clearTimeout(self.dragTimeout);
|
|
|
|
self.dragTimeout = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:22 +00:00
|
|
|
function dragpauseTrack(e) {
|
2011-05-13 15:44:50 +00:00
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-12 20:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mousedownTrack(e) {
|
2011-05-12 11:15:32 +00:00
|
|
|
setPosition(getPosition(e));
|
2011-05-13 15:44:50 +00:00
|
|
|
self.video.currentTime = self.options.position;
|
2011-05-12 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:22 +00:00
|
|
|
function mouseleaveTrack(e) {
|
2011-05-12 11:15:32 +00:00
|
|
|
self.$tooltip.hide();
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:22 +00:00
|
|
|
function mousemoveTrack(e) {
|
2011-05-12 11:15:32 +00:00
|
|
|
self.$tooltip.options({
|
2011-05-14 19:32:49 +00:00
|
|
|
title: formatPosition(getPosition(e))
|
|
|
|
}).show(e);
|
2011-05-12 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function parsePositionInput(str) {
|
2011-05-14 19:32:49 +00:00
|
|
|
var split = str.split(':').reverse();
|
2011-05-13 15:44:50 +00:00
|
|
|
while (split.length > 3) {
|
|
|
|
split.pop();
|
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
return split.reduce(function(prev, curr, i) {
|
2011-05-13 15:44:50 +00:00
|
|
|
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
|
2011-05-14 19:32:49 +00:00
|
|
|
}, 0);
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function playing() {
|
2011-05-14 19:32:49 +00:00
|
|
|
self.options.position = self.video.currentTime;
|
2011-05-13 15:44:50 +00:00
|
|
|
if (
|
|
|
|
(self.options.playInToOut || self.playInToOut) &&
|
|
|
|
self.options.position >= self.options.out
|
|
|
|
) {
|
2011-05-14 19:32:49 +00:00
|
|
|
///*
|
2011-05-13 15:44:50 +00:00
|
|
|
togglePaused();
|
|
|
|
setPosition(self.options.out);
|
2011-05-14 19:32:49 +00:00
|
|
|
//self.video.currentTime = self.options.position;
|
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
|
|
|
//*/
|
|
|
|
//ended();
|
|
|
|
self.playInToOut = false;
|
2011-05-13 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
setPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
function playInToOut() {
|
|
|
|
self.playInToOut = true;
|
|
|
|
setPosition(self.options['in']);
|
|
|
|
self.video.currentTime = self.options['in'];
|
|
|
|
if (self.options.paused) {
|
|
|
|
togglePaused();
|
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function progress() {
|
|
|
|
var buffered = self.video.buffered;
|
|
|
|
for (var i = 0; i < buffered.length; i++) {
|
|
|
|
self.buffered[i] = [buffered.start(i), buffered.end(i)];
|
|
|
|
// fixme: firefox weirdness
|
|
|
|
if (self.buffered[i][0] > self.buffered[i][1]) {
|
|
|
|
self.buffered[i][0] = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$progress.attr({
|
|
|
|
src: getProgressImageURL()
|
|
|
|
});
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function seeked() {
|
2011-05-15 07:26:00 +00:00
|
|
|
clearTimeout(self.seekTimeout);
|
2011-05-13 15:44:50 +00:00
|
|
|
hideLoadingIcon();
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$playIcon && self.$playIcon.show();
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function seeking() {
|
2011-05-15 07:26:00 +00:00
|
|
|
self.seekTimeout = setTimeout(function() {
|
|
|
|
self.$playIcon && self.$playIcon.hide();
|
|
|
|
showLoadingIcon();
|
|
|
|
}, 250);
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
function setPosition(position) {
|
|
|
|
if (!Ox.isUndefined(position)) {
|
|
|
|
self.options.position = Ox.limit(position, self['in'], self['out']);
|
|
|
|
}
|
|
|
|
self.options.position = Math.round(
|
|
|
|
self.options.position * self.options.fps
|
|
|
|
) / self.options.fps;
|
|
|
|
if (self.iconIsVisible) {
|
|
|
|
self.$playIcon.animate({
|
|
|
|
opacity: 0
|
|
|
|
}, 250);
|
|
|
|
self.iconIsVisible = false;
|
|
|
|
}
|
|
|
|
if (self.posterIsVisible) {
|
|
|
|
self.$poster.animate({
|
|
|
|
opacity: 0
|
|
|
|
}, 250);
|
|
|
|
self.posterIsVisible = false;
|
|
|
|
}
|
|
|
|
self.$subtitle && setSubtitle();
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$timeline && self.$positionMarker.css(getCSS('positionMarker'));
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$position && self.$position.html(formatPosition());
|
|
|
|
}
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
function getCSS(element) {
|
|
|
|
var css;
|
2011-05-15 07:52:37 +00:00
|
|
|
if (element == 'controls' || element == 'titlebar') {
|
2011-05-15 07:26:00 +00:00
|
|
|
css = {
|
|
|
|
width: self.width + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'loadingIcon') {
|
|
|
|
css = {
|
|
|
|
left: self.iconLeft + 'px',
|
|
|
|
top: self.iconTop + 'px',
|
|
|
|
width: self.iconSize + 'px',
|
|
|
|
height: self.iconSize + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'logo') {
|
|
|
|
var logoHeight = Math.round(self.height / 10);
|
|
|
|
self.logoMargin = Math.round(self.height / 20);
|
|
|
|
css = {
|
2011-05-14 19:32:49 +00:00
|
|
|
left: self.logoMargin + 'px',
|
|
|
|
top: self.logoMargin + 'px',
|
|
|
|
height: logoHeight + 'px',
|
2011-05-15 07:26:00 +00:00
|
|
|
};
|
|
|
|
} else if (element == 'player') {
|
2011-05-15 07:52:37 +00:00
|
|
|
css = Ox.extend({
|
2011-05-15 07:26:00 +00:00
|
|
|
width: self.width + 'px',
|
|
|
|
height: (self.options.fullscreen
|
|
|
|
? window.innerHeight
|
|
|
|
: self.height + (
|
|
|
|
self.options.externalControls
|
|
|
|
? (!!self.options.controls.length + !!self.options.title) * self.barHeight
|
|
|
|
: 0)) + 'px'
|
2011-05-15 07:52:37 +00:00
|
|
|
}, self.options.fullscreen ? {
|
|
|
|
left: 0,
|
|
|
|
top: 0
|
|
|
|
} : {}, self.exitFullscreen ? {
|
|
|
|
left: self.absoluteOffset.left,
|
|
|
|
top: self.absoluteOffset.top
|
|
|
|
} : {});
|
2011-05-15 07:26:00 +00:00
|
|
|
} else if (element == 'playIcon') {
|
|
|
|
var playIconPadding = Math.round(self.iconSize * 1/8),
|
|
|
|
playIconSize = self.iconSize - 2 * playIconPadding - 4;
|
|
|
|
css = {
|
|
|
|
left: self.iconLeft + 'px',
|
|
|
|
top: self.iconTop + 'px',
|
2011-05-14 19:32:49 +00:00
|
|
|
width: playIconSize + 'px',
|
|
|
|
height: playIconSize + 'px',
|
|
|
|
padding: playIconPadding + 'px',
|
2011-05-15 07:26:00 +00:00
|
|
|
borderRadius: Math.round(self.iconSize / 2) + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'positionMarker') {
|
|
|
|
var position = self.options.duration ?
|
|
|
|
(self.options.position - self['in']) / self.options.duration : 0;
|
|
|
|
css = {
|
|
|
|
marginLeft: position * self.timelineImageWidth -
|
|
|
|
self.timelineImageWidth - 8 + 'px',
|
|
|
|
};
|
2011-05-15 07:52:37 +00:00
|
|
|
} else if (element == 'poster' || element == 'video') {
|
|
|
|
var playerWidth = self.width,
|
|
|
|
playerHeight = self.height,
|
|
|
|
playerRatio = playerWidth / playerHeight,
|
|
|
|
videoWidth = self.video.videoWidth,
|
|
|
|
videoHeight = self.video.videoHeight,
|
|
|
|
videoRatio = videoWidth / videoHeight,
|
|
|
|
videoIsWider = videoRatio > playerRatio,
|
|
|
|
width, height;
|
|
|
|
if (self.options.scaleToFill) {
|
|
|
|
width = videoIsWider ? playerHeight * videoRatio : playerWidth;
|
|
|
|
height = videoIsWider ? playerHeight : playerWidth / videoRatio;
|
|
|
|
} else {
|
|
|
|
width = videoIsWider ? playerWidth : playerHeight * videoRatio;
|
|
|
|
height = videoIsWider ? playerWidth / videoRatio : playerHeight;
|
|
|
|
}
|
|
|
|
width = Math.round(width);
|
|
|
|
height = Math.round(height);
|
2011-05-15 07:26:00 +00:00
|
|
|
css = {
|
2011-05-15 07:52:37 +00:00
|
|
|
width: width + 'px',
|
|
|
|
height: height + 'px',
|
|
|
|
marginLeft: parseInt((playerWidth - width) / 2),
|
|
|
|
marginTop: parseInt((playerHeight - height) / 2)
|
2011-05-15 07:26:00 +00:00
|
|
|
};
|
|
|
|
} else if (element == 'progress') {
|
|
|
|
css = {
|
|
|
|
width: self.timelineImageWidth + 'px',
|
|
|
|
marginLeft: -self.timelineImageWidth + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'subtitle') {
|
|
|
|
css = {
|
|
|
|
bottom: parseInt(self.height / 16) + 'px',
|
|
|
|
width: self.width + 'px',
|
|
|
|
fontSize: parseInt(self.height / 20) + 'px',
|
|
|
|
WebkitTextStroke: (self.height / 1000) + 'px rgb(0, 0, 0)'
|
|
|
|
};
|
2011-05-15 07:52:37 +00:00
|
|
|
} else if (element == 'space' || element == 'timeline') {
|
2011-05-15 07:26:00 +00:00
|
|
|
css = {
|
|
|
|
width: self.timelineWidth + 'px'
|
|
|
|
};
|
2011-05-15 07:52:37 +00:00
|
|
|
} else if (element == 'timelineImage' || element == 'timelineImages') {
|
2011-05-15 07:26:00 +00:00
|
|
|
css = {
|
|
|
|
width: self.timelineImageWidth + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'timelineInterface') {
|
|
|
|
css = {
|
|
|
|
width: self.timelineWidth + 'px',
|
|
|
|
marginLeft: -self.timelineWidth + 'px'
|
|
|
|
};
|
|
|
|
} else if (element == 'videoContainer') {
|
|
|
|
css = {
|
|
|
|
width: self.width + 'px',
|
|
|
|
height: self.height + 'px'
|
|
|
|
};
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
2011-05-15 07:26:00 +00:00
|
|
|
return css;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSizes(callback) {
|
|
|
|
var ms = callback ? 250 : 0;
|
|
|
|
self.width = self.options.fullscreen ? window.innerWidth : self.options.width;
|
|
|
|
self.height = self.options.fullscreen ? window.innerHeight : self.options.height;
|
|
|
|
self.iconSize = Math.max(Math.round(self.height / 10), 16),
|
|
|
|
self.iconLeft = parseInt((self.width - self.iconSize) / 2),
|
|
|
|
self.iconTop = parseInt((self.height - self.iconSize) / 2);
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.$timeline || self.$space) {
|
2011-05-15 07:26:00 +00:00
|
|
|
self.timelineWidth = self.width - self.options.controls.reduce(function(prev, curr) {
|
2011-05-14 19:32:49 +00:00
|
|
|
return prev + (
|
|
|
|
curr == 'timeline' || curr == 'space' ? 0 :
|
|
|
|
curr == 'position' ? self.positionWidth : 16
|
|
|
|
);
|
|
|
|
}, 0);
|
|
|
|
if (self.$timeline) {
|
2011-05-15 07:26:00 +00:00
|
|
|
self.timelineImageWidth = self.timelineWidth - self.barHeight;
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-15 07:26:00 +00:00
|
|
|
that.animate(getCSS('player'), ms, callback);
|
|
|
|
self.$videoContainer.animate(getCSS('videoContainer'), ms);
|
|
|
|
self.loaded && self.$video.animate(getCSS('video'), ms);
|
|
|
|
self.$poster && self.$poster.animate(getCSS('poster'), ms);
|
|
|
|
self.$logo && self.$logo.animate(getCSS('logo'), ms);
|
|
|
|
self.$loadingIcon.animate(getCSS('loadingIcon'), ms);
|
|
|
|
self.$playIcon && self.$playIcon.animate(getCSS('playIcon'), ms);
|
|
|
|
self.$subtitle && self.$subtitle.animate(getCSS('subtitle'), ms);
|
|
|
|
self.$titlebar && self.$titlebar.animate(getCSS('titlebar'), ms);
|
|
|
|
self.$controls && self.$controls.animate(getCSS('controls'), ms);
|
|
|
|
if (self.$timeline) {
|
|
|
|
self.$timeline.animate(getCSS('timeline'), ms);
|
|
|
|
self.$timelineImages.animate(getCSS('timelineImages'), ms);
|
|
|
|
self.$timelineImage.animate(getCSS('timelineImage'), ms);
|
|
|
|
self.$progress && self.$progress.animate(getCSS('progress'), ms);
|
|
|
|
self.$positionMarker.animate(getCSS('positionMarker'), ms);
|
|
|
|
self.$timelineInterface.animate(getCSS('timelineInterface'), ms);
|
|
|
|
}
|
|
|
|
self.$space && self.$space.animate(getCSS('space'), ms);
|
2011-05-12 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-12 22:12:41 +00:00
|
|
|
function setSubtitle() {
|
|
|
|
var subtitle = getSubtitle();
|
|
|
|
if (subtitle != self.subtitle) {
|
|
|
|
self.subtitle = subtitle;
|
|
|
|
self.$subtitle.html(
|
|
|
|
Ox.highlight(self.subtitle, self.options.find, 'Ox.Highlight')
|
|
|
|
.replace(/\n/g, '<br/>')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function showInterface() {
|
|
|
|
clearTimeout(self.controlsTimeout);
|
2011-05-14 19:32:49 +00:00
|
|
|
that.find('.OxInterface').animate({
|
2011-05-12 10:51:17 +00:00
|
|
|
opacity: 1
|
2011-05-13 15:44:50 +00:00
|
|
|
}, 250);
|
|
|
|
self.$logo && self.$logo.animate({
|
|
|
|
top: self.logoMargin + 16 + 'px',
|
|
|
|
opacity: 0.5
|
|
|
|
}, 250, function() {
|
|
|
|
self.options.logoLink && self.$logo
|
|
|
|
.bind({
|
|
|
|
click: function() {
|
|
|
|
document.location.href = self.options.logoLink;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.options.logoTitle && self.$logo
|
|
|
|
.bind({
|
2011-05-14 19:32:49 +00:00
|
|
|
mouseenter: function(e) {
|
|
|
|
self.$logoTooltip.show(e);
|
|
|
|
},
|
2011-05-13 15:44:50 +00:00
|
|
|
mouseleave: self.$logoTooltip.hide
|
2011-05-14 19:32:49 +00:00
|
|
|
});
|
2011-05-13 15:44:50 +00:00
|
|
|
});
|
|
|
|
self.$subtitle.animate({
|
|
|
|
bottom: self.barHeight + parseInt(self.options.height / 16) + 'px',
|
|
|
|
});
|
2011-05-12 10:51:17 +00:00
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
|
|
|
|
function showLoadingIcon() {
|
|
|
|
self.$loadingIcon.attr({
|
|
|
|
src: Ox.UI.getImagePath('symbolLoadingAnimated.svg')
|
|
|
|
.replace('/classic/', '/modern/')
|
2011-05-14 19:32:49 +00:00
|
|
|
}).show();
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitPositionInput() {
|
|
|
|
self.$positionInput.hide();
|
|
|
|
self.$position.html('').show();
|
|
|
|
setPosition(parsePositionInput(self.$positionInput.options('value')));
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.loaded) {
|
|
|
|
self.video.currentTime = self.options.position;
|
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
if (self.wasPlaying) {
|
2011-05-14 19:32:49 +00:00
|
|
|
togglePaused();
|
2011-05-13 15:44:50 +00:00
|
|
|
self.video.play();
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$playButton && self.$playButton.toggleTitle();
|
2011-05-13 15:44:50 +00:00
|
|
|
self.wasPlaying = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-15 07:26:00 +00:00
|
|
|
function toggleFullscreen() {
|
2011-05-15 07:52:37 +00:00
|
|
|
var parentOffset, wasPlaying;
|
2011-05-15 07:26:00 +00:00
|
|
|
self.options.fullscreen = !self.options.fullscreen;
|
|
|
|
if (!self.options.paused) {
|
|
|
|
self.video.pause();
|
|
|
|
wasPlaying = true;
|
|
|
|
}
|
|
|
|
if (self.options.fullscreen) {
|
|
|
|
self.$parent = that.parent();
|
2011-05-15 07:52:37 +00:00
|
|
|
parentOffset = self.$parent.offset();
|
|
|
|
self.absoluteOffset = that.offset();
|
|
|
|
self.relativeOffset = {
|
|
|
|
left: self.absoluteOffset.left - parentOffset.left,
|
|
|
|
top: self.absoluteOffset.top - parentOffset.top
|
|
|
|
};
|
2011-05-15 07:26:00 +00:00
|
|
|
that.detach()
|
|
|
|
.css({
|
2011-05-15 07:52:37 +00:00
|
|
|
left: self.absoluteOffset.left + 'px',
|
|
|
|
top: self.absoluteOffset.top + 'px',
|
2011-05-15 07:26:00 +00:00
|
|
|
zIndex: 1000
|
|
|
|
})
|
|
|
|
.appendTo(Ox.UI.$body);
|
|
|
|
setSizes(function() {
|
|
|
|
wasPlaying && self.video.play();
|
|
|
|
});
|
|
|
|
} else {
|
2011-05-15 07:52:37 +00:00
|
|
|
self.exitFullscreen = true;
|
2011-05-15 07:26:00 +00:00
|
|
|
setSizes(function() {
|
|
|
|
that.detach()
|
|
|
|
.css({
|
2011-05-15 07:52:37 +00:00
|
|
|
left: self.relativeOffset.left + 'px',
|
|
|
|
top: self.relativeOffset.top + 'px'
|
2011-05-15 07:26:00 +00:00
|
|
|
})
|
|
|
|
.appendTo(self.$parent);
|
|
|
|
wasPlaying && self.video.play();
|
2011-05-15 07:52:37 +00:00
|
|
|
self.exitFullscreen = false;
|
2011-05-15 07:26:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function toggleMuted() {
|
|
|
|
self.options.muted = !self.options.muted;
|
|
|
|
self.video.muted = self.options.muted;
|
2011-05-12 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
function togglePaused() {
|
|
|
|
self.options.paused = !self.options.paused;
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$timeline && self.$positionMarkerRing.css({
|
2011-05-13 15:44:50 +00:00
|
|
|
borderColor: 'rgba(255, 255, 255, ' + (self.options.paused ? 0.5 : 1) + ')'
|
2011-05-12 10:39:48 +00:00
|
|
|
});
|
2011-05-13 15:44:50 +00:00
|
|
|
if (self.options.paused) {
|
|
|
|
self.video.pause();
|
|
|
|
clearInterval(self.playInterval);
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.showIcon) {
|
|
|
|
togglePlayIcon();
|
|
|
|
self.options.showIcon && self.$playIcon.animate({
|
|
|
|
opacity: 1
|
|
|
|
}, 250);
|
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
} else {
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.playInToOut && self.options.position > self.options.out - self.secondsPerFrame) {
|
|
|
|
setPosition(self.options['in']);
|
|
|
|
self.video.currentTime = self.options.position;
|
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
self.video.play();
|
|
|
|
self.playInterval = setInterval(playing, self.millisecondsPerFrame);
|
2011-05-14 19:32:49 +00:00
|
|
|
if (self.options.showIcon) {
|
|
|
|
self.options.showIcon && self.$playIcon.animate({
|
|
|
|
opacity: 0
|
2011-05-15 07:26:00 +00:00
|
|
|
}, 250, togglePlayIcon);
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePlayIcon() {
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$playIcon.attr({
|
|
|
|
src: Ox.UI.getImagePath(
|
|
|
|
'symbol' + (self.options.paused ? 'Play' : 'Pause'
|
|
|
|
)+ '.svg').replace('/classic/', '/modern/')
|
|
|
|
});
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleScale() {
|
|
|
|
self.options.scaleToFill = !self.options.scaleToFill;
|
2011-05-15 07:26:00 +00:00
|
|
|
self.$video.animate(getCSS('video'), 250);
|
2011-05-15 07:52:37 +00:00
|
|
|
self.$poster && self.$poster.animate(getCSS('poster'), 250);
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSize() {
|
|
|
|
self.options.sizeIsLarge = !self.options.sizeIsLarge;
|
|
|
|
that.triggerEvent('size', {
|
|
|
|
size: self.options.sizeIsLarge ? 'large' : 'small'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-05-15 07:26:00 +00:00
|
|
|
if (key == 'fullscreen') {
|
|
|
|
toggleFullscreen();
|
|
|
|
} else if (key == 'height' || key == 'width') {
|
2011-05-14 19:32:49 +00:00
|
|
|
setSizes();
|
2011-05-13 15:44:50 +00:00
|
|
|
} else if (key == 'muted') {
|
|
|
|
toggleMuted();
|
2011-05-14 19:32:49 +00:00
|
|
|
self.$muteButton && self.$muteButton.toggleTitle();
|
2011-05-13 15:44:50 +00:00
|
|
|
} else if (key == 'paused') {
|
|
|
|
togglePaused();
|
|
|
|
} else if (key == 'position') {
|
|
|
|
setPosition();
|
2011-05-14 19:32:49 +00:00
|
|
|
} else if (key == 'scaleToFill') {
|
|
|
|
self.$video.css(getVideoCSS());
|
2011-05-13 15:44:50 +00:00
|
|
|
}
|
2011-05-14 19:32:49 +00:00
|
|
|
};
|
2011-05-12 10:39:48 +00:00
|
|
|
|
2011-05-13 15:44:50 +00:00
|
|
|
that.playInToOut = function() {
|
2011-05-14 19:32:49 +00:00
|
|
|
playInToOut();
|
2011-05-13 15:44:50 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-05-12 10:39:48 +00:00
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|