| 1 |
<?php // $Id: movino_players.inc,v 1.6 2007/10/02 03:41:25 tomsun Exp $
|
| 2 |
/*
|
| 3 |
Movino Web Frontend - Integration with external players
|
| 4 |
Copyright 2006, 2007 Tom Sundström
|
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify
|
| 7 |
it under the terms of the GNU General Public License version 2 as
|
| 8 |
published by the Free Software Foundation.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public
|
| 16 |
License along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
*/
|
| 19 |
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Returns an array containing information on all
|
| 23 |
* installed embedded players compattible with Movino.
|
| 24 |
*
|
| 25 |
* Example:
|
| 26 |
*
|
| 27 |
* $players['cortado'] = array(
|
| 28 |
* '#name' => t('Cortado'),
|
| 29 |
* '#callback' => 'movino_player_cortado_callback',
|
| 30 |
* );
|
| 31 |
*
|
| 32 |
* @return array
|
| 33 |
*/
|
| 34 |
function movino_player_list() {
|
| 35 |
return module_invoke_all('movino_player');
|
| 36 |
}
|
| 37 |
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Display a video by embedding a player.
|
| 41 |
* Select which of the installed player to use
|
| 42 |
* by looking at the 'encoding' parameter of the video.
|
| 43 |
*
|
| 44 |
* @param array $video
|
| 45 |
* @return string of HTML
|
| 46 |
*/
|
| 47 |
function movino_player($video) {
|
| 48 |
|
| 49 |
// Figure out what formats the installed players support.
|
| 50 |
$support = module_invoke_all('movino_player_supports');
|
| 51 |
|
| 52 |
if (isset($support[$video['encoding']])) {
|
| 53 |
$players = movino_player_list();
|
| 54 |
$callback = $players[$support[$video['encoding']]]['#callback'];
|
| 55 |
return call_user_func($callback, $video);
|
| 56 |
}
|
| 57 |
|
| 58 |
// Did not find a suitable player - return an unsupported message.
|
| 59 |
return theme('movino_player_unsupported', $video);
|
| 60 |
}
|
| 61 |
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Theme a generic embedded player
|
| 65 |
*
|
| 66 |
* @param array $video
|
| 67 |
* @param array $extra_params
|
| 68 |
*/
|
| 69 |
function theme_movino_player_embed($player_name, $params, $extra_params = array()) {
|
| 70 |
$extra_params_embed = '';
|
| 71 |
$extra_params_object = '';
|
| 72 |
|
| 73 |
if (!empty($extra_params)) {
|
| 74 |
foreach($extra_params as $pname => $pval) {
|
| 75 |
$extra_params_embed .= "\n $pname=\"$pval\"";
|
| 76 |
$extra_params_object .= "\n <param name=\"$pname\" value=\"$pval\"/>";
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
// Read resize parameters.
|
| 81 |
if (movino_player_embed_allow_resize($params)) {
|
| 82 |
if (isset($_REQUEST['movino-ps'])
|
| 83 |
&& $_REQUEST['movino-ps'] >= movino_player_embed_scale_min()
|
| 84 |
&& $_REQUEST['movino-ps'] <= movino_player_embed_scale_max()
|
| 85 |
)
|
| 86 |
{
|
| 87 |
$params['width'] = $_REQUEST['movino-ps'] * $params['width'];
|
| 88 |
$params['height'] = $_REQUEST['movino-ps'] * $params['height'];
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
$size_attrib = ' style="width: '. $params['width'] . 'px; height: '. $params['height'] .'px; "';
|
| 93 |
|
| 94 |
$output = <<<END
|
| 95 |
<div id="movino-player"{$size_attrib}>
|
| 96 |
<object id="{$player_name}-object"
|
| 97 |
classid="{$params['classid']}"
|
| 98 |
width="{$params['width']}"
|
| 99 |
height="{$params['height']}"
|
| 100 |
align="{$params['align']}"
|
| 101 |
code="{$params['code']}"
|
| 102 |
codebase="{$params['codebase']}"
|
| 103 |
>
|
| 104 |
<param name="archive" value="{$params['archive']}"/>
|
| 105 |
<param name="url" value="{$params['url']}"/>{$extra_params_object}
|
| 106 |
|
| 107 |
<comment>
|
| 108 |
<embed id="cortado-embed" type="application/x-java-applet"
|
| 109 |
width="{$params['width']}"
|
| 110 |
height="{$params['height']}"
|
| 111 |
align="{$params['align']}"
|
| 112 |
code="{$params['code']}"
|
| 113 |
archive="{$params['archive']}"
|
| 114 |
codebase="{$params['codebase']}"
|
| 115 |
url="{$params['url']}"{$extra_params_embed}
|
| 116 |
>
|
| 117 |
<noembed>You need Java to view this media file.</noembed>
|
| 118 |
</embed>
|
| 119 |
</comment>
|
| 120 |
</object>
|
| 121 |
</div>
|
| 122 |
END;
|
| 123 |
|
| 124 |
if (movino_player_embed_allow_resize($params)) {
|
| 125 |
$output .= theme('movino_player_embed_resize', $params);
|
| 126 |
}
|
| 127 |
|
| 128 |
return $output;
|
| 129 |
}
|
| 130 |
|
| 131 |
|
| 132 |
/**
|
| 133 |
* Theme embed resize control.
|
| 134 |
*/
|
| 135 |
function theme_movino_player_embed_resize($video) {
|
| 136 |
|
| 137 |
$output = '';
|
| 138 |
$ps = (isset($_REQUEST['movino-ps']) ? $_REQUEST['movino-ps'] : 1);
|
| 139 |
|
| 140 |
if ($ps > movino_player_embed_scale_min()) {
|
| 141 |
$output .= l('-', $_REQUEST['q'], NULL, 'movino-ps=' . ($ps - 1));
|
| 142 |
}
|
| 143 |
if ($ps < movino_player_embed_scale_max()) {
|
| 144 |
$output .= l('+', $_REQUEST['q'], NULL, 'movino-ps=' . ($ps + 1));
|
| 145 |
}
|
| 146 |
|
| 147 |
if (empty($output)) {
|
| 148 |
return '';
|
| 149 |
}
|
| 150 |
|
| 151 |
return '<div id="resize-larger" style="margin-left: ' . $video['width'] . 'px ">' . $output . '</div>';
|
| 152 |
}
|
| 153 |
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Theme the 'unsupported video format' message.
|
| 157 |
*/
|
| 158 |
function theme_movino_player_unsupported($video) {
|
| 159 |
return '<div id="movino-player" class="error">'. t('No video player installed for @encoding content.', array('@encoding' => $video['encoding']))
|
| 160 |
. ' '
|
| 161 |
. (user_access('administer Movino')
|
| 162 |
? t('<a href="http://drupal.org/project/movino">Find</a> (or implement) a Movino-targeted Drupal module providing this functionality, then <a href="' . url('admin/build/modules') . '">install</a> and <a href="' . url('admin/settings/movino/players') . '">configure</a> it.')
|
| 163 |
: t('Contact the site administrator.')
|
| 164 |
).'</div>';
|
| 165 |
}
|