Exemple #1
0
 /**
  * jwplayer::play()
  * Will render and play the jwplayer video player
  * 
  * @param mixed $file
  * @param mixed $params
  * @return void
  */
 static function play($file = null, $params = null)
 {
     $output = '';
     // extract the params
     if (!empty($params) && is_array($params)) {
         extract($params);
     }
     // First the js file. Must be included. But only once.
     $js = !empty($js) ? $js : self::$js;
     if (self::$js_included === false) {
         echo '<script type="text/javascript" src="' . $js . '"></script>' . "\n";
         self::$js_included = true;
     }
     // The ID. Usually the database ID of the video. If not included, a random # will be picked.
     $div_id = !empty($id) ? self::$id_prefix . $id : self::$id_prefix . rand(10, 9999);
     // Build the argument list in this array
     $jw_args = array();
     // The jw arguments
     if (is_array($file)) {
         $jw_args['playlist'] = stripslashes(json_encode($file));
         if (!empty($playlist) && $playlist == true || !empty($playlist_position) || !empty($playlist_size)) {
             $jw_args['playlist.position'] = !empty($playlist_position) ? $playlist_position : self::$playlist_position;
             $jw_args['playlist.size'] = !empty($playlist_size) ? $playlist_size : self::$playlist_size;
         }
     } else {
         $jw_args['file'] = $file;
     }
     // path to the player.swf
     $swf = !empty($swf) ? $swf : self::$swf;
     $jw_args['id'] = !empty($playerID) ? $playerID : 'playerID';
     $jw_args['width'] = !empty($width) ? $width : self::$default_width;
     $jw_args['height'] = !empty($height) ? $height : self::$default_height;
     $jw_args['flashplayer'] = $swf;
     $jw_args['image'] = !empty($image) ? $image : null;
     $jw_args['autostart'] = !empty($autostart) ? $autostart : self::$autostart;
     // A class name for the divs.
     $className = !empty($class) ? $class : self::$classname;
     // A bit of math. If we have a video player AND a playlist width, add them up to get a new video player size.
     if (!empty($jw_args['playlist.size'])) {
         $jw_args['width'] = $jw_args['width'] + $jw_args['playlist.size'];
     }
     // Place holder div for the video player
     echo "<div id='" . $div_id . "' class='" . $className . "'></div>\n";
     echo "<script>jwplayer('" . $div_id . "').setup({\n";
     foreach ($jw_args as $key => $value) {
         if ($key == 'playlist') {
             echo "'" . $key . "': " . $value . ",\n";
         } else {
             if (!empty($value)) {
                 echo "'" . $key . "': '" . $value . "',\n";
             }
         }
     }
     echo "});</script>\n";
 }
Exemple #2
0
Easily set new dimensions
<?php 
jwplayer::play('http://www.youtube.com/watch?v=yrDXseJRJIk', array('width' => 600, 'height' => 360));
?>
The code: <br />
<code>jwplayer::play('http://www.youtube.com/watch?v=yrDXseJRJIk', array(<br />
	'width' => 600,<br />
	'height' => 360<br />
));</code>
</div>
</div>
<div style="clear: both;"></div>
<div style="margin: 20px 0px 20px 0px;">
Include more than one file for a playlist!
<?php 
jwplayer::play(array(array('file' => 'http://www.youtube.com/watch?v=f_J5rBxeTIk', 'title' => 'Universe Song', 'description' => 'Animaniacs sing the Universe Song'), array('file' => 'http://www.youtube.com/watch?v=EhiJwfj0URs', 'title' => 'Nations Of The World', 'description' => 'Animaniacs sing the Nations of the World (HQ)'), array('file' => 'http://www.youtube.com/watch?v=sNUDDaEOvuY', 'title' => '50 State Capitols', 'description' => 'Animaniacs sing the 50 States and their Capitols')), array('playlist' => true, 'width' => 480, 'height' => 360));
?>
The Code: <br />
<code>jwplayer::play(array(<br />
		&nbsp;&nbsp;&nbsp;array('file' => 'http://www.youtube.com/watch?v=f_J5rBxeTIk', 'title' => 'Universe Song', 'description' => 'Animaniacs sing the Universe Song'), <br />
		&nbsp;&nbsp;&nbsp;array('file' => 'http://www.youtube.com/watch?v=EhiJwfj0URs', 'title' => 'Nations Of The World', 'description' => 'Animaniacs sing the Nations of the World (HQ)'), <br />
		&nbsp;&nbsp;&nbsp;array('file' => 'http://www.youtube.com/watch?v=sNUDDaEOvuY', 'title' => '50 State Capitols', 'description' => 'Animaniacs sing the 50 States and their Capitols')<br />
	),<br />
	array('playlist' => true, 'width' => 480, 'height' => 360));
	</code>
</div>

<h3>Available params:</h3>
<ul>
<li>id - The ID tacked on to the div and script code that references that div</li>
<li>playerID - The ID of the actual player itself. Defaults to playerID.</li>