0

I am embedding a SoundCloud player using the /oembed call in the API.

First of all, it seems like the documentation is incorrect/outdated regarding the height of the iframe in the response. The docs says about the maxheight parameter:

The maximum height in px. The default is 81 for tracks and 305 for all other.

However, it seems like the actual received height values are 166px for tracks and 450px for sets.

Now to my actual question:

When calling /oembed for a set/playlist, there will be empty space below the track list. Is there any way to eliminate this space? In other words, can I somehow set the height of the received iframe based on the number of items in the playlist?

Checking this myself and setting the height dynamically won't work since I am not allowed to inspect the contents of the iframe, because of same-origin policy in the web browser.

Markus Amalthea Magnuson
  • 8,415
  • 4
  • 41
  • 49

1 Answers1

0

Thanks for spotting incorrect wording. We'll fix this ASAP.

Regarding your question, yes, you can send maxheight parameter in your query and set it to anything that makes sense for you.

The height of the "currently playing sound", together with caption for the current playlist is 196px, so to make the height of scrollable area where all the sounds are listed to be, say, 100px, you can do:

var div = document.createElement('div');

$.get(
  'http://soundcloud.com/oembed?' + 
  'url=http://soundcloud.com/eric' + 
  '&format=json&maxheight=296'
)
  .done(function (response) {
    div.innerHTML = response.html;
    document.body.appendChild(div);
  });

Here's a working example: http://jsbin.com/aduxex/1/edit

Misha Reyzlin
  • 13,736
  • 4
  • 54
  • 63
  • Thanks for your reply. Well, the maxheight parameter is available in the HTML5 widget too, but since I do not know beforehand what height I want the problem is the same. (And I really don't want to use the Flash widget.) If only the oEmbed response contained a key/value with the number of list items in the returned widget, I could at least fetch that, calculate a height, and then call it again. The nice thing about the /oembed call is that it takes any kind of SoundCloud URL; I think all API calls should allow that. Where can I leave such feature request? – Markus Amalthea Magnuson Nov 12 '12 at 15:40
  • OK, I understand that your goal is to adjust the widget so that it would have certain size that would match exactly the amount of tracks? – Misha Reyzlin Nov 12 '12 at 15:51
  • Yes, that is exactly what I want :) Without knowing the number of tracks in advance, I want to paint a widget that is always a height that fits all tracks, but no higher than that. – Markus Amalthea Magnuson Nov 12 '12 at 15:56
  • You could query the API for the given playlist and see how many tracks are there for this playlist. One item is 59px at the default zoom level and font-size. – Misha Reyzlin Nov 12 '12 at 15:57
  • Yeah, that would work I suppose, although adding complexity to the close-to-one-line nicety of the oembed call. Well, thank you very much for your help! – Markus Amalthea Magnuson Nov 12 '12 at 16:02
  • Thing is, the height of one item actually depends on the type of the playlist – so for sets one item is 24px, and for users tracks, it's 59px. Then if you have very long track names for a playlist – it will become two lines, extending the height of one item to be 48px. So perhaps it's not a very scalable idea :( – Misha Reyzlin Nov 12 '12 at 16:05