/**
* Output jPlayer
*
* @since deTube 1.0
*/
function dp_jplayer($args = array()) {
$defaults = array(
'swfpath' => get_template_directory_uri().'/js',
'poster' => '',
'files' => array(),
'supplied' => '',
'width' => null,
'height' => null,
'type' => null,
'solution' => 'html,flash',
'autoplay' => false,
'id' => '',
'container_id' => '',
'player_id' => '',
'media_id' => '',
'gui_id' => ''
);
$args = wp_parse_args($args, $defaults);
extract($args);
if(empty($files))
return false;
wp_enqueue_script('jquery-jplayer');
// Set unique ID
if(!$id)
$id = md5(uniqid(rand()));
if(!$container_id)
$container_id = 'jp-container-'.$id;
if(!$player_id)
$player_id = 'jp-player-'.$id;
if(!$media_id)
$media_id = 'jp-media-'.$id;
if(!$gui_id)
$gui_id = 'jp-gui-'.$id;
$media = '';
$formats = array(
'mp4', 'm4v', 'm4a',
'ogg', 'ogv', 'oga',
'webm', 'webmv', 'webma',
'flv', 'fla',
'mp3',
'wav'
);
if(empty($supplied)) {
$i = 0;
$_supplied = array();
foreach($files as $file) {
$file = trim($file);
$format = pathinfo($file, PATHINFO_EXTENSION);
if($format == 'mp4') {
$format = ($type == 'audio') ? 'm4a' : 'm4v';
$solution = 'flash, html';
} elseif($format == 'ogg') {
$format = ($type == 'audio') ? 'oga' : 'ogv';
} elseif($format == 'webm') {
$format = ($type == 'audio') ? 'webma' : 'webmv';
} elseif($format == 'mov')
$format = 'm4v';
if(in_array($format, $formats)) {
if($i != 0)
$media .= ',';
$_supplied[] = $format;
$media .= $format.':"'.$file.'"';
$i++;
}
}
$supplied = array_unique($_supplied);
$supplied = implode(',', $supplied);
}
if($poster)
$media .= ',poster:"'.$poster.'"';
if($width)
$data_width = $width;
else
$data_width = 480;
if($height)
$data_height = $height;
else
$data_height = 270;
if($width)
$width = $width.'px';
else
$width = '100%';
if($height)
$height = $height.'px';
$size = '';
if($width)
$size .= 'width:"'.$width.'",';
if($height)
$size .= 'height:"'.$height.'"';
?>