function videojs_preprocess_videojs_formatter_videojs in Video.js (HTML5 Video Player) 6.2
Preprocess function for videojs.tpl.php when using a playlist.
File
- includes/
videojs.theme.inc, line 10 - Theme and preprocess functions for the Video.js module.
Code
function videojs_preprocess_videojs_formatter_videojs(&$vars) {
$field_name = $vars['element']['#field_name'];
$node = $vars['element']['#node'];
$vars['player_id'] = $node->nid . '-' . str_replace('_', '-', $field_name);
$vars['items'] = (array) $node->{$field_name};
$vars['attributes'] = array(
'width' => intval(variable_get('videojs_width', 640)),
'height' => intval(variable_get('videojs_height', 264)),
);
// Find the poster images
$poster_field = variable_get('videojs_' . $node->type, 'video_module');
if ($poster_field == 'video_module') {
if (!empty($vars['items'][0]['data']['video_thumb'])) {
// Video module present, retrieving description and poster image from first video
$vars['items']['thumbnail'] = $vars['items'][0]['data']['video_thumb'];
}
}
else {
// Grab any poster image from a field defined in videojs admin settings
if (!empty($node->{$poster_field})) {
// Take the first image from field
$vars['items']['thumbnail'] = $node->{$poster_field}[0];
}
}
// Preprocess link fields
$field = content_fields($field_name, $node->type);
if ($field['type'] == 'link') {
$links = $vars['items'];
$vars['items'] = array();
foreach ($links as $link) {
if (!empty($link['title']) && strncmp('video/', $link['title'], 6) === 0) {
$link['filemime'] = $link['title'];
}
elseif (substr($link['url'], -5) == '.webm') {
$link['filemime'] = 'video/webm';
}
else {
$link['filemime'] = file_get_mimetype($link['url']);
// If the mime type is application/octet-stream, default to MP4.
// This happens for instance for links without extensions.
if ($link['filemime'] == 'application/octet-stream') {
$link['filemime'] = 'video/mp4';
}
}
$link['url'] = url($link['url'], $link);
if (strncmp($link['filemime'], 'image/', 6) == 0) {
$vars['items']['thumbnail'] = $link;
}
else {
$vars['items'][] = $link;
}
}
}
template_preprocess_videojs($vars);
}