From 74d7b5848a42e30e669cc05db22e83396b3cc107 Mon Sep 17 00:00:00 2001 From: Calin Burloiu Date: Wed, 17 Aug 2011 13:55:28 +0300 Subject: [PATCH] working on widget video resizing integration --- application/config/config.php | 2 +- application/config/p2p-tube.php | 2 +- application/controllers/catalog.php | 5 +- application/models/videos_model.php | 13 ++-- application/views/video/watch_view.php | 45 ++++++------- js/jquery.ui.nsvideo.js | 93 +++++++++++++++++++------- 6 files changed, 98 insertions(+), 62 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index a0c644e..1402953 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -69,7 +69,7 @@ $config['url_suffix'] = ''; | than english. | */ -$config['language'] = 'romanian'; +$config['language'] = 'english'; /* |-------------------------------------------------------------------------- diff --git a/application/config/p2p-tube.php b/application/config/p2p-tube.php index b6a6e46..8eddbff 100644 --- a/application/config/p2p-tube.php +++ b/application/config/p2p-tube.php @@ -46,7 +46,7 @@ $config['default_js'] = ''; /* |-------------------------------------------------------------------------- -| Default Video File Extension +| Default Video File Extension (OBSOLETE) |-------------------------------------------------------------------------- | | Sets the default video file extension, which must be set without '.' prefix. diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 3285c67..fec8d64 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -57,10 +57,9 @@ class Catalog extends CI_Controller { { $this->load->helper('url'); - $str = '[{"def":"1080p"},{"def":"600p"}]'; - $a = json_decode($str); + $str = '800x600'; - echo count($a); + echo substr($str, strpos($str, 'x') + 1); } public function category($category_id, $offset = 0) diff --git a/application/models/videos_model.php b/application/models/videos_model.php index 536c92d..3a5ab05 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -101,9 +101,9 @@ class Videos_model extends CI_Model { * * all columns form DB with some exceptions that are overwritten or new * * formats content is moved in assets * * assets => list of associative lists where each one represents a - * video asset having keys: "src", "def" and "ext". Value of key "src" is - * the video torrent formated as - * {name}_{format}.{default_video_ext}.{default_torrent_ext} + * video asset having keys: "src", "res", "par" and "ext". Value of key + * "src" is the video torrent formated as + * {name}_{format}.{video_ext}.{default_torrent_ext} * * user_name => TODO: user name from `users` table * * category_title => a human-friendly category name * * tags => associative list of "tag => score" @@ -134,16 +134,15 @@ class Videos_model extends CI_Model { unset($video['formats']); $video['tags'] = json_decode($video['tags'], TRUE); asort($video['tags']); - $video['tags'] = array_reverse($video['tags'], true); + $video['tags'] = array_reverse($video['tags'], TRUE); // Torrents $video['url'] = array(); foreach ($video['assets'] as & $asset) { - $ext = isset($asset['ext']) ? - $asset['ext'] : $this->config->item('default_video_ext'); + $def = substr($asset['res'], strpos($asset['res'], 'x') + 1) . 'p'; $asset['src'] = site_url('data/torrents/'. $video['name'] . '_' - . $asset['def'] . '.'. $ext + . $def . '.'. $asset['ext'] . '.'. $this->config->item('default_torrent_ext')); } diff --git a/application/views/video/watch_view.php b/application/views/video/watch_view.php index b5f7eea..2036a32 100644 --- a/application/views/video/watch_view.php +++ b/application/views/video/watch_view.php @@ -91,15 +91,7 @@ }); // Switch video plugin facilities - $('#video-widget-tabs').tabs(); /*{ - ajaxOptions: { - type: "POST", - data: { url: "" }, - error: function(xhr, status, index, anchor) { - $(anchor.hash).html('Could not load the video plugin.'); - } - } - });*/ + $('#video-widget-tabs').tabs(); $('#switch-to-ns-html5') .click(function() { $('#video-widget') @@ -110,23 +102,24 @@ $('#video-widget') .nsvideo('type', 'ns-vlc'); }); - + // Video widget - $('#video-widget').nsvideo({ - type: "", - definition: - "", - src: { - - } - }); + $('#video-widget') + .nsvideo({ + type: "", + src: , + //width: videoWidth, + //height: videoHeight + minWidth: 1200, + maxWidth: 1400 + }) + .resize(function(e) { + $('#video-widget-tabs') + .css('width', $('#video-widget').css('width')); + console.log($('#video-widget').css('width')); + }); + + $('#video-widget-tabs') + .css('width', $('#video-widget').css('width')); }); \ No newline at end of file diff --git a/js/jquery.ui.nsvideo.js b/js/jquery.ui.nsvideo.js index 31b7c4c..fd33153 100644 --- a/js/jquery.ui.nsvideo.js +++ b/js/jquery.ui.nsvideo.js @@ -16,8 +16,11 @@ $.widget( "ui.nsvideo", { version: "1.0.0 beta", options: { type: 'ns-html5', - width: 320, - height: 240, + srcIndex: 0, + width: 0, + height: 0, + minWidth: 0, + maxWidth: 0, showStatus: true, refreshInterval: 0.1, // seconds autoplay: false @@ -86,26 +89,27 @@ $.widget( "ui.nsvideo", { widget.videoPlugin('fullscreen'); }); - // Video definition buttonset + // Video format buttonset if (typeof widget.options.src == 'object') { - var $definitions = $('
') + var $formats = $('
') .appendTo(widget.$controls); - $definitions = $('.ui-nsvideo-definitions', $definitions[0]); + $formats = $('.ui-nsvideo-formats', $formats[0]); $.each(widget.options.src, function(index, value) { - id = widget.element.attr('id') + '-def-' + index; - $('') - .appendTo($definitions) - .attr('checked', (index == widget.options.definition)) + id = widget.element.attr('id') + '-format-' + index; + definition = value.res.substring(value.res.indexOf('x')+1)+'p'; + $('') + .appendTo($formats) + .attr('checked', (index == widget.options.srcIndex)) .click(function() { widget.videoPlugin('pause'); - widget.definition(index); + widget.srcIndex(index); }); - $('') - .appendTo($definitions); + $('') + .appendTo($formats); }); - $definitions.buttonset(); + $formats.buttonset(); } // Volume @@ -148,7 +152,7 @@ $.widget( "ui.nsvideo", { // Initialize video plugin widget.$video.ready(function() { - widget.videoPlugin('init'); + //widget.videoPlugin('init'); }); }, @@ -192,8 +196,8 @@ $.widget( "ui.nsvideo", { // Select video source. // If src option is string, that's the source. - // If src is an object, properties are definitions and values are - // sources. + // If src is an object, there is a list of associative arrays, each + // one having the mandatory keys "src" and "res" (resolution). var src = widget.crtSrc(); if (src == null) return widget; @@ -270,6 +274,42 @@ $.widget( "ui.nsvideo", { widget.$video.css('position', 'relative'); + // Adjust video size for auto-resizing within ranges minWidth and + // maxWidth. + if (widget.options.minWidth != 0 && widget.options.maxWidth != 0 + && typeof widget.options.src == 'object' + && (typeof widget.options.src[ widget.options.srcIndex ].res) + != 'undefined' + && (typeof widget.options.src[ widget.options.srcIndex ].dar) + != 'undefined') + { + var resolution = widget.options.src[ widget.options.srcIndex ].res; + var dar = widget.options.src[ widget.options.srcIndex ].dar; + var darL = parseInt( + dar.substring(0, dar.indexOf(':'))); + var darR = parseInt( + dar.substring(dar.indexOf(':') + 1)); + var videoHeight = parseInt( + resolution.substring(resolution.indexOf('x') + 1)); + var videoWidth = Math.round(videoHeight * darL / darR); + // Video width must be between minWidth and maxWidth pixels. + if (videoWidth > widget.options.maxWidth) + { + videoHeight = Math.round(widget.options.maxWidth / videoWidth + * videoHeight); + videoWidth = widget.options.maxWidth; + } + else if (videoWidth < widget.options.minWidth) + { + videoHeight = Math.round(widget.options.minWidth / videoWidth + * videoHeight); + videoWidth = widget.options.minWidth; + } + console.log(videoWidth + ' ' + videoHeight); + widget.$video.css('width', videoWidth); + widget.$video.css('height', videoHeight); + } + widget._setWidgetWidth(); }, @@ -284,8 +324,11 @@ $.widget( "ui.nsvideo", { + 'px'); } else + { widget.element.css('width', - widget.$video.width + 8 + 'px'); + widget.$video.width() + 8 + 'px'); + widget.$video.css('left', '0'); + } }, setPlayButton: function() { @@ -346,13 +389,15 @@ $.widget( "ui.nsvideo", { return null; }, - definition: function(def) { + srcIndex: function(srcIndex) { var widget = this; - if (typeof def == 'undefined') - return widget.options.definition; + if (typeof srcIndex == 'undefined') + return widget.options.srcIndex; + + widget.options.srcIndex = srcIndex; - widget.options.definition = def; + // Refresh. widget.video(); return widget; @@ -383,14 +428,14 @@ $.widget( "ui.nsvideo", { src = widget.options.src; else if (typeof widget.options.src == 'object') { - if (typeof widget.options.definition == 'undefined') + if (typeof widget.options.srcIndex == 'undefined') return null; - if (typeof widget.options.src[ widget.options.definition ] + if (typeof widget.options.src[ widget.options.srcIndex ].src == 'undefined') return null; - src = widget.options.src[ widget.options.definition ]; + src = widget.options.src[ widget.options.srcIndex ].src; } if (widget.options.type == 'ns-html5') -- 2.20.1