From 568629fb347de799ebf0589190832ae8748c19c7 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 13 May 2011 17:44:50 +0200 Subject: [PATCH] add scale (fill/fit) functionality to video player --- demos/video/js/video.js | 14 +- source/Ox.UI/js/Video/Ox.VideoElement.js | 1 + source/Ox.UI/js/Video/Ox.VideoPlayer.js | 1098 ++++++++++++++-------- 3 files changed, 732 insertions(+), 381 deletions(-) diff --git a/demos/video/js/video.js b/demos/video/js/video.js index bcdb2ec0..e266560d 100644 --- a/demos/video/js/video.js +++ b/demos/video/js/video.js @@ -9,12 +9,18 @@ Ox.load('UI', { padding: '16px' }); Ox.VideoPlayer({ + controls: ['play', 'mute', 'size', 'scale', 'timeline', 'position'], height: 96 * 384/180,//96 * 256/180, + logoLink: 'http://next.0xdb.org/' + id, + logoTitle: 'Watch on 0xdb', + logo: 'png/logo.png', + paused: true, + scaleToFill: true, subtitles: 'srt/' + id + '.srt', - timelineURL: timeline, - title: 'Brick', - videoURL: url, - width: 384//256 + timeline: timeline, + title: 'Brick - Rian Johnson - 2005', + video: url, + width: 500//384//256 }).appendTo(Ox.UI.$body); /* var id = '0133093'; diff --git a/source/Ox.UI/js/Video/Ox.VideoElement.js b/source/Ox.UI/js/Video/Ox.VideoElement.js index c1df1e6e..23b6406a 100644 --- a/source/Ox.UI/js/Video/Ox.VideoElement.js +++ b/source/Ox.UI/js/Video/Ox.VideoElement.js @@ -1,4 +1,5 @@ // vim: et:ts=4:sw=4:sts=4:ft=js + Ox.VideoElement = function(options, self) { var self = self || {}, diff --git a/source/Ox.UI/js/Video/Ox.VideoPlayer.js b/source/Ox.UI/js/Video/Ox.VideoPlayer.js index d70b2e07..15d9ff92 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPlayer.js +++ b/source/Ox.UI/js/Video/Ox.VideoPlayer.js @@ -1,11 +1,59 @@ /*@ -Ox.VideoPlayer Generic Video Player Element +Ox.VideoPlayer Generic Video Player (options, self) -> Video Player options Options - subtitles URL or SRT or subtitles object - start Start (sec) - stop Stop (sec) + annotation <[o]> Array of annotation tracks + name Name of the annotation track + data <[o]> Annotation data + in In point (sec) + out Out point (sec) + text 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 Duration (sec) + enableKeyboard If true, enable keyboard controls + externalControls If true, controls are outside the video + focus focus on 'click', 'load' or 'mouseover' + fps Frames per second + height Height in px (excluding external controls) + in In point (sec) + keepIconVisible If true, play icon stays visible after mouseleave + keepLargeTimelineVisible If true, large timeline stays visible after mouseleave + keepLogoVisible If true, logo stays visible after mouseleave + logo Logo image URL + logoLink Logo link URL + logoTitle Text for tooltip + muted If true, video is muted + paused If true, video is paused + playInToOut If true, video plays only from in to out + position Initial position (sec) + poster Poster URL + posterFrame Position of poster frame (sec) + preload 'auto', 'metadata' or 'none' + out Out point (sec) + scaleToFill If true, scale to fill (otherwise, scale to fit) + showControlsOnLoad If true, show controls on load + showFind If true, show find input + showHours If true, don't show hours for videos shorter than one hour + showIcon If true, show play icon + showIconOnLoad If true, show icon on load + showLargeTimeline If true, show large timeline + showMilliseconds If true, show milliseconds + showPointMarkers If true, show in/out markers + sizeIsLarge If true, initial state of the size control is large + subtitles URL or SRT or array of subtitles + in In point (sec) + out Out point (sec) text Text + timeline Timeline image URL + title Video title + type 'play', 'in' or 'out' + video Video URL + volume Volume (0-1) + width Width in px @*/ Ox.VideoPlayer = function(options, self) { @@ -13,32 +61,57 @@ Ox.VideoPlayer = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ - autoplay: false, - height: 192, + annotations: [], + controls: [], + duration: -1, + enableKeyboard: false, + externalControls: false, + focus: 'click', + fps: 25, + height: 144, + 'in': -1, + keepIconVisible: false, + keepLargeTimelineVisible: false, + keepLogoVisible: false, + logo: '', logoLink: '', logoTitle: '', - logoURL: '', + muted: false, + paused: false, + playInToOut: false, position: 0, - showControls: false, - showVolume: false, + poster: '', + preload: 'auto', + out: -1, + scaleToFill: false, + showControlsOnLoad: false, + showFind: false, + showHours: false, + showIcon: false, + showIconOnLoad: false, + showLargeTimeline: false, + showMilliseconds: false, + showPointMarkers: false, subtitles: [], - timelineURL: '', + timeline: '', title: '', - videoURL: '', + type: 'play', + video: '', + volume: 1, width: 256 }) .options(options || {}) .css({ - position: 'absolute', - width: self.options.width + 'px', - height: self.options.height + 'px' - //background: 'red' - }) - .bind({ - mouseenter: showControls, - mouseleave: hideControls + position: 'absolute' }); + if (self.options.controls.length || self.options.showIcon || self.options.title) { + that.bind({ + mouseenter: showInterface, + mouseleave: hideInterface + }); + } + if (Ox.isString(self.options.subtitles)) { if (self.options.subtitles.indexOf('\n') > -1) { self.options.subtitles = Ox.parseSRT(self.options.subtitles); @@ -50,64 +123,56 @@ Ox.VideoPlayer = function(options, self) { } } + // fixme: this is _relative_, resizing can happen + self.ratio = self.options.width / self.options.height; + self.barHeight = 16; + setSize(); + + self.millisecondsPerFrame = 1000 / self.options.fps; + self.buffered = []; self.controlsTimeout; self.dragTimeout; - self.controlsHeight = 16; - self.outerTrackWidth = self.options.width - 96; - self.innerTrackWidth = self.outerTrackWidth - self.controlsHeight; - self.markerOffset = -self.innerTrackWidth - 8; - - self.$video = Ox.VideoElement({ - height: self.options.height, - paused: true, - url: self.options.videoURL, - width: self.options.width - }) + self.$videoContainer = $('
') .css({ position: 'absolute', + width: self.options.width + 'px', + height: self.options.height + 'px', + overflow: 'hidden' }) - .bindEvent({ + .appendTo(that.$element) + + self.$video = $('