working on widget video resizing integration
authorCalin Burloiu <calin.burloiu@gmail.com>
Wed, 17 Aug 2011 10:55:28 +0000 (13:55 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Wed, 17 Aug 2011 10:55:28 +0000 (13:55 +0300)
application/config/config.php
application/config/p2p-tube.php
application/controllers/catalog.php
application/models/videos_model.php
application/views/video/watch_view.php
js/jquery.ui.nsvideo.js

index a0c644e..1402953 100644 (file)
@@ -69,7 +69,7 @@ $config['url_suffix'] = '';
 | than english.
 |
 */
-$config['language']    = 'romanian';
+$config['language']    = 'english';
 
 /*
 |--------------------------------------------------------------------------
index b6a6e46..8eddbff 100644 (file)
@@ -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. 
index 3285c67..fec8d64 100644 (file)
@@ -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)
index 536c92d..3a5ab05 100644 (file)
@@ -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'));
                }
                
index b5f7eea..2036a32 100644 (file)
                });
                
                // Switch video plugin facilities
-               $('#video-widget-tabs').tabs(); /*{
-                       ajaxOptions: {
-                               type: "POST",
-                               data: { url: "<?php //echo $video['url'][0] ?>" },
-                               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')
                                $('#video-widget')
                                        .nsvideo('type', 'ns-vlc');
                        });
-                       
+               
                // Video widget
-               $('#video-widget').nsvideo({
-                       type: "<?php echo $plugin_type ?>",
-                       definition:
-                               "<?php echo $video['assets'][ $asset_index ]['def'] ?>",
-                       src: {
-                               <?php 
-                                       for ($i=0; $i < count($video['assets']); $i++)
-                                       {
-                                               $asset = $video['assets'][$i];
-                                               echo '"'. $asset['def'] . '": ';
-                                               echo '"'. $asset['src'] . '"'; 
-                                               echo ($i == count($video['assets']) - 1) ? '' : ', ';
-                                       }
-                               ?>
-                       }
-               });
+               $('#video-widget')
+                       .nsvideo({
+                               type: "<?php echo $plugin_type ?>",
+                               src: <?php echo json_encode($video['assets']) ?>,
+                               //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'));
        });
 </script>
\ No newline at end of file
index 31b7c4c..fd33153 100644 (file)
@@ -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 = $('<form><div class="ui-nsvideo-definitions ui-nsvideo-control-right"></div></form>')
+                       var $formats = $('<form><div class="ui-nsvideo-formats ui-nsvideo-control-right"></div></form>')
                                .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;
-                               $('<input type="radio" id="' + id + '" name="definition" />')
-                                       .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';
+                               $('<input type="radio" id="' + id + '" name="format" />')
+                                       .appendTo($formats)
+                                       .attr('checked', (index == widget.options.srcIndex))
                                        .click(function() {
                                                widget.videoPlugin('pause');
-                                               widget.definition(index);
+                                               widget.srcIndex(index);
                                        });
-                               $('<label for="' + id + '">' + index + '</label>')
-                                       .appendTo($definitions);
+                               $('<label for="' + id + '">' + definition + '</label>')
+                                       .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')