diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/css/gallery.css | 6 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 69 | ||||
-rw-r--r-- | modules/gallery/views/movieplayer.html.php | 61 |
3 files changed, 102 insertions, 34 deletions
diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css index 9d773699..7e711156 100644 --- a/modules/gallery/css/gallery.css +++ b/modules/gallery/css/gallery.css @@ -143,6 +143,12 @@ width: 1%; } +/* Unsupported movie download link ~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +.g-movie-download-link { + text-align: center; +} + /** ******************************************************************* * 2) Admin **********************************************************************/ diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 931da382..8f127532 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -663,31 +663,70 @@ class Item_Model_Core extends ORM_MPTT { } /** - * Return a flowplayer <script> tag for movies + * Return a view for movies. By default this is a Flowplayer v3 <script> tag, but + * movie_img events can override this and provide their own player/view. If no player/view + * is found and the movie is unsupported by Flowplayer v3, this returns a simple download link. * @param array $extra_attrs * @return string */ public function movie_img($extra_attrs) { - $v = new View("movieplayer.html"); $max_size = module::get_var("gallery", "resize_size", 640); $width = $this->width; $height = $this->height; - if ($width > $max_size || $height > $max_size) { - if ($width > $height) { - $height = (int)($height * $max_size / $width); - $width = $max_size; + if ($width == 0 || $height == 0) { + // Not set correctly, likely because ffmpeg isn't available. Making the window 0x0 causes the + // video to be effectively unviewable. So, let's guess: set width to max_size and guess a + // height (using 4:3 aspect ratio). Once the video metadata is loaded, js in + // movieplayer.html.php will correct these values. + $width = $max_size; + $height = ceil($width * 3/4); + } + $attrs = array_merge(array("id" => "g-item-id-{$this->id}"), $extra_attrs, + array("class" => "g-movie")); + + // Run movie_img events, which can either: + // - generate a view, which is used in place of the standard Flowplayer v3 player + // (use view variable) + // - alter the arguments sent to the standard player + // (use fp_params and fp_config variables) + $movie_img = new stdClass(); + $movie_img->max_size = $max_size; + $movie_img->width = $width; + $movie_img->height = $height; + $movie_img->attrs = $attrs; + $movie_img->url = $this->file_url(true); + $movie_img->fp_params = array(); // additional Flowplayer params values (will be json encoded) + $movie_img->fp_config = array(); // additional Flowplayer config values (will be json encoded) + $movie_img->view = array(); + module::event("movie_img", $movie_img, $this); + + if (count($movie_img->view) > 0) { + // View generated - use it + $view = implode("\n", $movie_img->view); + } else { + // View NOT generated - see if filetype supported by Flowplayer v3 + // Note that the extension list below is hard-coded and doesn't use the legal_file helper + // since anything else will not work in Flowplayer v3. + if (in_array(strtolower(pathinfo($this->name, PATHINFO_EXTENSION)), + array("flv", "mp4", "m4v", "mov", "f4v"))) { + // Filetype supported by Flowplayer v3 - use it (default) + $view = new View("movieplayer.html"); + $view->max_size = $movie_img->max_size; + $view->width = $movie_img->width; + $view->height = $movie_img->height; + $view->attrs = $movie_img->attrs; + $view->url = $movie_img->url; + $view->fp_params = $movie_img->fp_params; + $view->fp_config = $movie_img->fp_config; } else { - $width = (int)($width * $max_size / $height); - $height = $max_size; + // Filetype NOT supported by Flowplayer v3 - display download link + $attrs = array_merge($attrs, array("style" => "width: {$max_size}px;", + "download" => $this->name, // forces download (HTML5 only) + "class" => "g-movie g-movie-download-link")); + $view = html::anchor($this->file_url(true), t("Click here to download item."), $attrs); } } - - $v->attrs = array_merge($extra_attrs, array("style" => "width:{$width}px;height:{$height}px", - "class" => "g-movie")); - if (empty($v->attrs["id"])) { - $v->attrs["id"] = "g-item-id-{$this->id}"; - } - return $v; + return $view; } /** diff --git a/modules/gallery/views/movieplayer.html.php b/modules/gallery/views/movieplayer.html.php index 343eafe8..25cb9f58 100644 --- a/modules/gallery/views/movieplayer.html.php +++ b/modules/gallery/views/movieplayer.html.php @@ -1,26 +1,49 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<?= html::anchor($item->file_url(true), "", $attrs) ?> +<?= html::anchor($url, "", $attrs) ?> <script type="text/javascript"> - flowplayer( - "<?= $attrs["id"] ?>", - { - src: "<?= url::abs_file("lib/flowplayer.swf") ?>", - wmode: "transparent", - provider: "pseudostreaming" - }, - { - clip: { - scaling: 'fit' - }, - plugins: { - pseudostreaming: { - url: "<?= url::abs_file("lib/flowplayer.pseudostreaming-byterange.swf") ?>" + var id = "<?= $attrs["id"] ?>"; + var max_size = <?= $max_size ?>; + // set the size of the movie html anchor, taking into account max_size and height of control bar + function set_movie_size(width, height) { + if((width > max_size) || (height > max_size)) { + if (width > height) { + height = Math.ceil(height * max_size / width); + width = max_size; + } else { + width = Math.ceil(width * max_size / height); + height = max_size; + } + } + height += flowplayer(id).getConfig().plugins.controls.height; + $("#" + id).css({width: width, height: height}); + }; + // setup flowplayer + flowplayer(id, + $.extend(true, { + "src": "<?= url::abs_file("lib/flowplayer.swf") ?>", + "wmode": "transparent", + "provider": "pseudostreaming" + }, <?= json_encode($fp_params) ?>), + $.extend(true, { + "plugins": { + "pseudostreaming": { + "url": "<?= url::abs_file("lib/flowplayer.pseudostreaming-byterange.swf") ?>" }, - controls: { - autoHide: 'always', - hideDelay: 2000 + "controls": { + "autoHide": "always", + "hideDelay": 2000, + "height": 24 + } + }, + "clip": { + "scaling": "fit", + "onMetaData": function(clip) { + // set movie size a second time using actual size from metadata + set_movie_size(parseInt(clip.metaData.width), parseInt(clip.metaData.height)); } } - } + }, <?= json_encode($fp_config) ?>) ).ipad(); + // set movie size using width and height passed from movie_img function + $("document").ready(set_movie_size(<?= $width ?>, <?= $height ?>)); </script> |