1 file.theme.inc theme_file_video($variables)

Returns HTML for displaying an HTML5 <video> tag.

Parameters

array $variables: An associative array containing:

  • file: Associative array of file data, which must include "uri".
  • controls: Boolean indicating whether or not controls should be displayed.
  • autoplay: Boolean indicating whether or not the video should start playing automatically.
  • loop: Boolean indicating whether or not the video should loop.
  • muted: Boolean indicating whether or not the sound should be muted.
  • width: Width, in pixels, of the video player.
  • height: Height, in pixels, of the video player.

Related topics

File

core/modules/file/file.theme.inc, line 485
Theme functions for the File module.

Code

function theme_file_video($variables) {
  $files = $variables['files'];
  $output = '';

  $video_attributes = array();
  if ($variables['controls']) {
    $video_attributes['controls'] = 'controls';
  }
  if ($variables['autoplay']) {
    $video_attributes['autoplay'] = 'autoplay';
  }
  if ($variables['loop']) {
    $video_attributes['loop'] = 'loop';
  }
  if ($variables['muted']) {
    $video_attributes['muted'] = 'muted';
  }
  if ($variables['width']) {
    $video_attributes['width'] = $variables['width'];
  }
  if ($variables['height']) {
    $video_attributes['height'] = $variables['height'];
  }
  if (!empty($variables['preload'])) {
    $video_attributes['preload'] = $variables['preload'];
  }

  $output .= '<video' . backdrop_attributes($video_attributes) . '>';
  foreach ($files as $delta => $file) {
    $source_attributes = array(
      'src' => file_create_url($file['uri']),
      'type' => $file['filemime'],
    );
    $output .= '<source' . backdrop_attributes($source_attributes) . ' />';
  }
  $output .= '</video>';
  return $output;
}