diff --git a/demos/video/js/video.js b/demos/video/js/video.js index e266560d..54e1bc44 100644 --- a/demos/video/js/video.js +++ b/demos/video/js/video.js @@ -2,37 +2,154 @@ Ox.load('UI', { debug: true, theme: 'modern' }, function() { - var id = '0393109'; - var url = 'http://next.0xdb.org/' + id + '/96p.webm?' + Ox.random(1000000); - var timeline = 'http://next.0xdb.org/' + id + '/timeline.16.png'; - Ox.UI.$body.css({ - 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', - timeline: timeline, - title: 'Brick - Rian Johnson - 2005', - video: url, - width: 500//384//256 + var id = '0393109', + poster = 'http://next.0xdb.org/' + id + '/poster.jpg', + timeline = 'http://next.0xdb.org/' + id + '/timeline.16.png', + url = 'http://next.0xdb.org/' + id + '/96p.webm', + videoSize = getVideoSize(), + $videos = [ + Ox.VideoPlayer({ + controls: ['play', 'mute', 'scale', 'timeline', 'position'], + enableKeyboard: true, + focus: 'mouseenter', + height: 192, + logoLink: 'http://next.0xdb.org/' + id, + logoTitle: 'Watch on 0xdb', + logo: 'png/logo.png', + paused: true, + poster: poster, + showIconOnLoad: true, + showProgress: false, + subtitles: 'srt/' + id + '.srt', + timeline: timeline, + title: 'Brick - Rian Johnson - 2005', + video: url + '?' + + Ox.random(1000000), + width: 360 + }) + .css({ + margin: '16px' + }), + Ox.VideoPlayer({ + height: 192, + 'in': 3128.725, + //keepIconVisible: true, + out: 3130.725, + paused: true, + playInToOut: true, + //preload: 'none', + showIcon: true, + showIconOnLoad: true, + timeline: timeline, + video: url + '?' + + Ox.random(1000000), + width: 360 + }) + .css({ + margin: '16px' + }), + Ox.VideoPlayer({ + controls: ['play', 'playInToOut', 'mute', 'size', 'space', 'position'], + externalControls: true, + height: videoSize.height, + 'in': 3128.725, + out: 3130.725, + paused: true, + showMilliseconds: 2, + subtitles: 'srt/' + id + '.srt', + timeline: timeline, + video: url + '?' + + Ox.random(1000000), + width: videoSize.width + }) + .css({ + margin: '16px' + }) + ]; + window.$videos = $videos + Ox.SplitPanel({ + elements: [ + { + element: Ox.SplitPanel({ + elements: [ + { + element: Ox.Element() + .append($videos[0]) + .bindEvent({ + resize: function(foo, size) { + $videos[0].options({height: size - 32}); + } + }), + size: 224, + resizable: true, + resize: [100, 400] + }, + { + element: Ox.Element() + } + ], + orientation: 'vertical' + }) + .bindEvent({ + resize: function(foo, size) { + $videos[0].options({width: size - 32}); + } + }), + size: 392, + resizable: true, + resize: [200, 600] + }, + { + element: Ox.Element() + .append($videos[1]) + .bindEvent({ + resize: resizeVideo + }) + }, + { + element: Ox.SplitPanel({ + elements: [ + { + element: Ox.Element() + .append($videos[2]) + .bindEvent({ + resize: function(foo, size) { + $videos[2].options({height: size - 48}); + } + }), + size: 240, + resizable: true, + resize: [100, 400] + }, + { + element: Ox.Element() + } + ], + orientation: 'vertical' + }) + .bindEvent({ + resize: function(foo, size) { + $videos[2].options({width: size - 32}); + } + }), + size: 392, + resizable: true, + resize: [200, 600] + } + ], + orientation: 'horizontal' }).appendTo(Ox.UI.$body); - /* - var id = '0133093'; - var url = 'http://next.0xdb.org/' + id + '/96p.webm?' + Ox.random(1000000); - var timeline = 'http://next.0xdb.org/' + id + '/timeline.16.png'; - Ox.VideoPlayer({ - height: 96 * 256/230, - timeline: timeline, - url: url, - width: 256 - }).css({ - left: '300px' - }).appendTo(Ox.UI.$body); - */ + + function getVideoSize() { + var size = {}, + widths = $videos ? $videos[0].options('width') + $videos[2].options('width') : 720 + size.width = window.innerWidth - widths - 98; + size.height = Math.round(size.width / 180 * 96); + return size; + } + function resizeVideo() { + var size = getVideoSize(); + $videos[1].options({ + width: size.width, + height: size.height + }); + } + }); diff --git a/source/Ox.UI/css/Ox.UI.css b/source/Ox.UI/css/Ox.UI.css index fa080f0c..9182d11c 100644 --- a/source/Ox.UI/css/Ox.UI.css +++ b/source/Ox.UI/css/Ox.UI.css @@ -1647,7 +1647,6 @@ Video margin-left: 4px; } - .OxVideoPlayer > .OxBar .OxInputGroup { //width: 98px; } diff --git a/source/Ox.UI/js/Video/Ox.VideoPlayer.js b/source/Ox.UI/js/Video/Ox.VideoPlayer.js index 15d9ff92..b99b732f 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPlayer.js +++ b/source/Ox.UI/js/Video/Ox.VideoPlayer.js @@ -35,14 +35,15 @@ Ox.VideoPlayer Generic Video Player 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 + showInterfaceOnLoad If true, show controls and title on load showLargeTimeline If true, show large timeline - showMilliseconds If true, show milliseconds + showMilliseconds Number of decimals to show showPointMarkers If true, show in/out markers + showProgress <|false> If true, show buffering progress sizeIsLarge If true, initial state of the size control is large subtitles URL or SRT or array of subtitles in In point (sec) @@ -63,13 +64,13 @@ Ox.VideoPlayer = function(options, self) { .defaults({ annotations: [], controls: [], - duration: -1, + duration: 86399, enableKeyboard: false, externalControls: false, focus: 'click', fps: 25, height: 144, - 'in': -1, + 'in': 0, keepIconVisible: false, keepLargeTimelineVisible: false, keepLogoVisible: false, @@ -82,16 +83,17 @@ Ox.VideoPlayer = function(options, self) { position: 0, poster: '', preload: 'auto', - out: -1, + out: 0, scaleToFill: false, - showControlsOnLoad: false, showFind: false, showHours: false, showIcon: false, showIconOnLoad: false, + showInterfaceOnLoad: false, showLargeTimeline: false, - showMilliseconds: false, + showMilliseconds: 0, showPointMarkers: false, + showProgress: false, subtitles: [], timeline: '', title: '', @@ -101,11 +103,50 @@ Ox.VideoPlayer = function(options, self) { width: 256 }) .options(options || {}) + .addClass('OxVideo') .css({ position: 'absolute' }); - if (self.options.controls.length || self.options.showIcon || self.options.title) { + 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; + + if (self.options.enableKeyboard) { + that.bindEvent({ + key_left: function() { + setPosition(self.options.position + self.secondsPerFrame); + }, + key_right: function() { + setPosition(self.options.position - self.secondsPerFrame); + }, + 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) { that.bind({ mouseenter: showInterface, mouseleave: hideInterface @@ -123,12 +164,6 @@ 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; @@ -137,10 +172,15 @@ Ox.VideoPlayer = function(options, self) { self.$videoContainer = $('
') .css({ position: 'absolute', - width: self.options.width + 'px', - height: self.options.height + 'px', + background: 'rgb(0, 0, 0)', overflow: 'hidden' }) + .bind({ + click: function() { + togglePaused(); + self.$playButton && self.$playButton.toggleTitle(); + } + }) .appendTo(that.$element) self.$video = $('