You are here

function theme_file_styles_video in Styles 7.2

Same name and namespace in other branches
  1. 7 contrib/file_styles/file_styles.theme.inc \theme_file_styles_video()

Support for HTML5 videos out of the box.

File

contrib/file_styles/file_styles.theme.inc, line 106
Theme functions for File styles.

Code

function theme_file_styles_video($variables) {
  $file = $variables['object'];
  $style_name = $variables['style_name'];
  $vars = array();
  $width = isset($variables['width']) ? $variables['width'] : NULL;
  $height = isset($variables['height']) ? $variables['height'] : NULL;
  $path = file_create_url($file->uri);
  $preset_name = $variables['preset_name'];
  $preset = styles_containers_available_styles('file', 'video', $preset_name);

  // By default, we don't display as a thumbnail.
  $thumbnail = FALSE;
  foreach ($preset['effects'] as $effect) {
    switch ($effect['name']) {
      case 'resize':
        $width = isset($effect['data']['width']) ? $effect['data']['width'] : $width;
        $height = isset($effect['data']['height']) ? $effect['data']['height'] : $height;
        break;
      case 'thumbnail':
        $thumbnail = TRUE;
        break;
    }
  }
  if (isset($variables['object']->override)) {
    $override = $variables['object']->override;
    $width = isset($override['width']) ? $override['width'] : $width;
    $height = isset($override['height']) ? $override['height'] : $height;
    if (isset($override['wysiwyg']) && $override['wysiwyg']) {
      $thumbnail = TRUE;
    }
  }
  $vars['attributes'] = array(
    'width' => $width,
    'height' => $height,
  );
  if ($thumbnail) {
    return theme('image', array(
      'path' => drupal_get_path('module', 'file_styles') . '/images/file-video.png',
      'attributes' => $vars['attributes'],
      'getsize' => FALSE,
    ));
  }
  $width = isset($vars['attributes']['width']) ? 'width="' . $vars['attributes']['width'] . '"' : '';
  $height = isset($vars['attributes']['height']) ? 'height="' . $vars['attributes']['height'] . '"' : '';
  switch ($file->filemime) {
    case 'video/ogg':
      $source = "<source src='{$path}' type='video/ogg; codecs=\"theora, vorbis\"'>";
      break;
    case 'video/mp4':
      $source = "<source src='{$path}' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'>";
      break;
  }
  $output = "<video {$width} {$height} controls>{$source}</video>";
  return $output;
}