1 file.theme.inc theme_file_audio($variables)

Returns HTML for displaying an HTML5 <audio> 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 audio should start playing automatically.
  • loop: Boolean indicating whether or not the audio should loop.

Related topics

File

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

Code

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

  $audio_attributes = array();
  if ($variables['controls']) {
    $audio_attributes['controls'] = 'controls';
  }
  if ($variables['autoplay']) {
    $audio_attributes['autoplay'] = 'autoplay';
  }
  if ($variables['loop']) {
    $audio_attributes['loop'] = 'loop';
  }
  if (!empty($variables['preload'])) {
    $audio_attributes['preload'] = $variables['preload'];
  }

  $output .= '<audio' . backdrop_attributes($audio_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 .= '</audio>';
  return $output;
}