Index: moodle/filter/mediaplugin/filter.php
--- moodle/filter/mediaplugin/filter.php Base (1.79)
+++ moodle/filter/mediaplugin/filter.php Locally Modified (Based On 1.79)
@@ -156,6 +156,7 @@

 function filter_mediaplugin_mp3_callback($link) {
     global $CFG, $OUTPUT, $PAGE;
+    $metadata = array('type'=>'mp3');

     $c = $OUTPUT->filter_mediaplugin_colors();   // You can set this up in your theme/xxx/config.php

@@ -199,7 +200,7 @@
     </div></noscript>
 OET;

-    $jsoutput = create_flowplayer($id, $url, 'mp3', $playercolors);
+    $jsoutput = create_flowplayer($id, $url, $metadata, $playercolors);
     $output .= $jsoutput;

     return $output;
@@ -275,17 +276,23 @@
     static $count = 0;
     $count++;
     $id = 'filter_flv_'.time().$count; //we need something unique because it might be stored in text cache
+    $url = trim(addslashes_js($link[1]));

-    $width  = empty($link[3]) ? '480' : $link[3];
-    $height = empty($link[4]) ? '360' : $link[4];
-    $url = addslashes_js($link[1]);
+    require_once($CFG->libdir.'/flvlib.php');
+    $filemetadata = array();
+    $filemetadata = external_flv_info($url);
+    $filemetadata['type'] = 'flv';

+
+    $width = $filemetadata['width'];
+    $height = $filemetadata['height'];
+
     $playerpath = $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf';

     $output = <<<EOT
     <span class="mediaplugin mediaplugin_flv" id="$id"></span>
     <noscript><div>
-    <object width="800" height="600" id="undefined" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
+    <object width="$width" height="$height" id="undefined" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
     <param name="movie" value="$playerpath" />
     <param name="allowfullscreen" value="true" />
     <param name="allowscriptaccess" value="always" />
@@ -296,7 +303,7 @@
     </div></noscript>
 EOT;

-    $jsoutput = create_flowplayer($id, $url, 'flv');
+    $jsoutput = create_flowplayer($id, $url, $filemetadata);
     $output .= $jsoutput;
     return $output;
 }
Index: moodle/lib/flvlib.php
--- moodle/lib/flvlib.php No Base Revision
+++ moodle/lib/flvlib.php Locally New
@@ -0,0 +1,68 @@
+<?PHP
+function internal_flv_info($file) {
+    $filehandle = $file->get_content_file_handle();
+    $content = fread($filehandle, 1024);
+    $info['width']  = get_flv_dimension($content, 'width');
+    $info['height'] = get_flv_dimension($content, 'height');
+
+    return $info;
+}
+
+function external_flv_info($fileurl, $resource_mod=false) {
+    global $CFG;
+
+    $info = array();
+
+    // read remote files
+    if (preg_match('/^(ht|f)tp:\/\//', $fileurl)) {
+        $ex = "curl -r 0-500 ".$fileurl;
+        $response = `$ex`;
+        $info['width']  = get_flv_dimension($response, 'width');
+        $info['height'] = get_flv_dimension($response, 'height');
+
+        return check_flv_dimension($info);
+    }
+
+
+}
+
+function default_flv_dimension () {
+    return array('width' => 400, 'height'=>320);
+}
+
+function check_flv_dimension($metadata) {
+    $default = default_flv_dimension();
+
+    if (empty($metadata) || ($metadata['width'] > $default['width'] || $metadata['height'] > $default['height'])) {
+        $metadata = default_flv_dimension();
+    }
+
+    return $metadata;
+}
+
+function get_flv_dimension($content, $field) {
+    $position = strpos($content, $field);
+    if($position === false) {
+        $default = default_flv_dimension();
+        if ($field == 'width') {
+            $defaultvalue = $default['width'];
+        } else {
+            $defaultvalue = $default['height'];
+        }
+        return $defaultvalue;
+
+    }
+    $position += strlen($field) + 2;
+    return flv_decode(ord($content[$position]), ord($content[$position + 1]));
+
+}
+
+function flv_decode($byte1, $byte2) {
+    $high1 = $byte1 >> 4;
+    $high2 = $byte2 >> 4;
+    $low1 = $byte1 & 0x0f;
+
+    $mantissa = ($low1 << 4) | $high2;
+
+    return ((256 + $mantissa) << $high1) >> 7;
+}
Index: moodle/lib/javascript-static.js
--- moodle/lib/javascript-static.js Base (1.173)
+++ moodle/lib/javascript-static.js Locally Modified (Based On 1.173)
@@ -1538,8 +2001,17 @@
     });
 };

-M.util.init_flvflowplayer = function (id, playerpath, fileurl) {
-    $f(id, playerpath, {
+M.util.init_flvflowplayer = function (id, playerpath, fileurl, fileinfo) {
+
+    if (fileinfo == null || fileinfo['width'] == '' || fileinfo['width'] == null) {
+        fileinfo['width'] = 400;
+    }
+
+    if (fileinfo == null ||  fileinfo['height'] == '' || fileinfo['height'] == null) {
+        fileinfo['height'] = 320;
+    }
+
+    $f(id,{src: playerpath, width: fileinfo['width'], height: fileinfo['height']}, {
         plugins: {
                 controls: {
                        autoHide: true
Index: moodle/lib/resourcelib.php
--- moodle/lib/resourcelib.php Base (1.18)
+++ moodle/lib/resourcelib.php Locally Modified (Based On 1.18)
@@ -241,18 +241,29 @@
  * @param string $clicktoopen
  * @return string html
  */
-function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) {
+function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen, $playersize = array()) {
     global $CFG, $PAGE;
+    require_once($CFG->libdir.'/flvlib.php');

     $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache

+
+    if(empty($playersize) || empty($playersize['width']) || empty($playersize['height'])) {
+        $playersize = default_flv_dimension();
+    }
+
+    $playersize = check_flv_dimension($playersize);
+
+    $width = $playersize['width'];
+    $height = $playersize['height'];
+
     $playerpath = $CFG->wwwroot .'/filter/mediaplugin/flvplayer.swf';

     $code = <<<EOT
 <div class="resourcecontent resourceflv">
   <span class="mediaplugin mediaplugin_flv" id="$id"></span>
   <noscript><div>
-    <object width="800" height="600" id="undefined" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
+    <object width="$width" height="$height" id="undefined" name="undefined" data="$playerpath" type="application/x-shockwave-flash">
     <param name="movie" value="$playerpath" />
     <param name="allowfullscreen" value="true" />
     <param name="allowscriptaccess" value="always" />
@@ -265,7 +276,7 @@
 EOT;

     $PAGE->requires->js('/lib/flowplayer.js');
-    $code .= $PAGE->requires->js_function_call('M.util.init_flvflowplayer', array('id'=>$id, 'playerpath'=>$playerpath, 'fileurl'=>$fullurl));
+    $code .= $PAGE->requires->js_function_call('M.util.init_flvflowplayer', array('id'=>$id, 'playerpath'=>$playerpath, 'fileurl'=>$fullurl, $playersize));
     return $code;
 }

Index: moodle/lib/weblib.php
--- moodle/lib/weblib.php Base (1.1485)
+++ moodle/lib/weblib.php Locally Modified (Based On 1.1485)
@@ -3257,15 +3282,15 @@
     return $jsoutput;
 }

-function create_flowplayer($id, $fileurl, $type='flv', $color='#000000') {
+function create_flowplayer($id, $fileurl, $metadata, $color='#000000') {
     global $CFG;

-    $playerpath = $CFG->wwwroot.'/filter/mediaplugin/'.$type.'player.swf';
+    $playerpath = $CFG->wwwroot.'/filter/mediaplugin/'.$metadata['type'].'player.swf';
     $jsoutput = html_writer::script('', $CFG->wwwroot.'/lib/flowplayer.js');

-    if ($type == 'flv') {
-        $jsoutput .= html_writer::script(js_writer::function_call('M.util.init_flvflowplayer', array($id, $playerpath, $fileurl)));
-    } else if ($type == 'mp3') {
+    if ($metadata['type'] == 'flv') {
+        $jsoutput .= html_writer::script(js_writer::function_call('M.util.init_flvflowplayer', array($id, $playerpath, $fileurl, $metadata)));
+    } else if ($metadata['type'] == 'mp3') {
         $audioplayerpath = $CFG->wwwroot .'/filter/mediaplugin/flowplayer.audio.swf';
         $jsoutput .= html_writer::script(js_writer::function_call('M.util.init_mp3flowplayerplugin', array($id, $playerpath, $audioplayerpath, $fileurl, $color)));
     }
Index: moodle/mod/data/lib.php
--- moodle/mod/data/lib.php Base (1.310)
+++ moodle/mod/data/lib.php Locally Modified (Based On 1.310)
@@ -1552,7 +1552,7 @@
     echo format_text($newtext, FORMAT_HTML, $options);
     echo '</td></tr>';

-    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="'.get_string('savesettings','data').'" /><input type="submit" name="resetadv" value="'.get_string('resetsettings','data').'" /></td></tr>';
+    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="'.get_string('search','data').'" /><input type="submit" name="resetadv" value="'.get_string('resetsettings','data').'" /></td></tr>';
     echo '</table>';
     echo '</div>';
     echo '</div>';
Index: moodle/mod/resource/locallib.php
--- moodle/mod/resource/locallib.php Base (1.14)
+++ moodle/mod/resource/locallib.php Locally Modified (Based On 1.14)
@@ -85,8 +85,11 @@
         $code = resourcelib_embed_mp3($fullurl, $title, $clicktoopen);

     } else if ($mimetype == 'video/x-flv') {
+        require_once ($CFG->libdir. '/flvlib.php');
+        $metadata = internal_flv_info($file);
+
         // Flash video file
-        $code = resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen);
+        $code = resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen, $metadata);

     } else if ($mimetype == 'application/x-shockwave-flash') {
         // Flash file
Index: moodle/mod/resource/styles.css
--- moodle/mod/resource/styles.css Base (1.4)
+++ moodle/mod/resource/styles.css Locally Modified (Based On 1.4)
@@ -1,6 +1,6 @@
 .path-mod-resource .popupnotice {text-align:center;margin:40px;}

-.resourcecontent object {height:600px;width:800px;}
+.resourcecontent.resourceflv {text-align: center;}
 .resourcecontent.resourcepdf object{height: 800px;width: 100%;}

 .resourcecontent .resourcemediaplugin_mp3 object {height:25px; }
