You are here

function emaudio_soundcloud_data in Media: SoundCloud 6

Implementation of hook_PROVIDER_data().

File

providers/soundcloud.inc, line 102
This include processes Soundcloud audio files for use by emaudio.module.

Code

function emaudio_soundcloud_data($field, $item) {

  // Create the initial data for the enclosure with the thumbnail and asset.
  $data = array(
    'emaudio_soundcloud_version' => 1,
  );

  // If the given code is between <object> tags, assume it's an actual embed
  // code rather than a URL, and return it directly.
  if (preg_match('/^<object.*<\\/object>.*/i', $item['embed'])) {
    $data['embed'] = TRUE;
    return $data;
  }
  $soundcloud_id = $item['value'];
  $data['id'] = $soundcloud_id;

  // Build up the parameters for the player.
  // See http://developers.soundcloud.com/docs/oembed.
  // Note that booleans have to passed as string representations.
  $oembed_parameters = array(
    'maxwidth' => $field['widget']['audio_width'],
    'maxheight' => $field['widget']['audio_height'],
    'show_comments' => variable_get('media_soundcloud_comments', TRUE) ? 'true' : 'false',
  );
  if ($field['widget']['audio_autoplay']) {
    $oembed_parameters['auto_play'] = 'true';
  }
  $color_play = variable_get('media_soundcloud_color_play', '');
  if ($color_play) {
    $oembed_parameters['color'] = $color_play;
  }
  $data['player'] = media_soundcloud_get_oembed_player($soundcloud_id, $oembed_parameters);

  // If any of the preview settings differ from the main ones, get a second
  // player for the preview.
  if ($field['widget']['preview_width'] != $field['widget']['audio_width'] || $field['widget']['preview_height'] != $field['widget']['audio_height'] || $field['widget']['preview_autoplay'] != $field['widget']['audio_autoplay']) {
    $oembed_parameters['maxwidth'] = $field['widget']['preview_width'];
    $oembed_parameters['maxheight'] = $field['widget']['preview_height'];

    // Have to explicitly set this in case it was earlier set to non-default.
    $oembed_parameters['auto_play'] = $field['widget']['preview_autoplay'] ? 'true' : 'false';
    $data['preview'] = media_soundcloud_get_oembed_player($soundcloud_id, $oembed_parameters);
  }
  return $data;
}