You are here

function media_soundcloud_get_oembed_player in Media: SoundCloud 6

Helper function to get an embedded player from SoundCloud.

Parameters

$soundcloud_id: The SoundCloud id.

$oembed_parameters: An array of parameters to pass in the oEmbed URL, in addition to the URL and format which are added in for you. For possible keys see http://developers.soundcloud.com/docs/oembed.

1 call to media_soundcloud_get_oembed_player()
emaudio_soundcloud_data in providers/soundcloud.inc
Implementation of hook_PROVIDER_data().

File

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

Code

function media_soundcloud_get_oembed_player($soundcloud_id, $oembed_parameters) {
  $oembed_parameters += array(
    'url' => EMAUDIO_SOUNDCLOUD_MAIN_URL . urldecode($soundcloud_id),
    'format' => 'json',
  );
  $url = url(EMAUDIO_SOUNDCLOUD_MAIN_URL . 'oembed', array(
    'query' => $oembed_parameters,
  ));
  $response = drupal_http_request($url);

  // Check the return code for the request.
  if ($response->code == 200) {

    // Code 200 assumes successful query of the soundcloud servers.
    $json = json_decode($response->data);
    $html = (string) $json->html;
    return $html;
  }
  else {

    // Any other code we'll assume is an error.
    drupal_set_message(t('SoundCloud server returned an error: @code @status', array(
      '@code' => $response->code,
      '@status' => $response->status_message,
    )));
  }
}