You are here

function audiofield_wavesurfer_player in AudioField 7

Callback function for AudioField wavesurfer.js player.

1 string reference to 'audiofield_wavesurfer_player'
audiofield_players in ./audiofield.players.inc
Implements hook_audiofield_players().

File

./audiofield.players.inc, line 461
Declares the available audio players for the Audio Field module.

Code

function audiofield_wavesurfer_player($player_path, $audio_file, $options) {
  $audio_title = $audio_file;
  if (!empty($options)) {
    if (!empty($options['item']['description'])) {
      $audio_title = $options['item']['description'];
    }
    elseif (!empty($options['item']['filename'])) {
      $audio_title = $options['item']['filename'];
    }
  }
  $player_base_path = variable_get('audiofield_players_dir', 'sites/all/libraries/player') . '/wavesurfer';
  drupal_add_js($player_base_path . '/dist/wavesurfer.min.js', array(
    'weight' => 0,
  ));

  // Generate a unique ID.
  $unique_id = drupal_html_id('wavesurfer-player-id');

  // Pass settings to builder.
  drupal_add_js(array(
    'audiofield' => array(
      $unique_id => file_create_url($audio_file),
    ),
  ), array(
    'type' => 'setting',
  ));

  // Add the builder javascript.
  drupal_add_js(drupal_get_path('module', 'audiofield') . '/js/wavesurfer.builder.js', array(
    'type' => 'file',
    'scope' => 'footer',
    'weight' => 10,
  ));

  // Add a default wavesurfer CSS.
  drupal_add_css(drupal_get_path('module', 'audiofield') . '/css/audiofield.wavesurfer.css');
  return theme('audiofield_players_wavesurfer_player', array(
    'container_id' => $unique_id,
    'audio_title' => $audio_title,
  ));
}