Nouvelle
Nouvelle

Reputation: 3

Implementing Soundcloud Player with Rails SDK

I´m a newbie rails developer, I´m trying to do a simple thing with rails and soundcloud but seems that after some days messing around with the API documentation can´t find the best way to do what I want.

Im trying to develop a contest for a local pub where DJ´s can send us their best track and they are voted to win a prize.

My approximation to this is storing the soundcloud url of his track in a database field and then this tracks are showed in the web through the little soundcloud player.

I think I can use this code in the view file.

<div id="player">
<object height="70" width="100%">
  <param name="movie" value="https://player.soundcloud.com/player.swf?    url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F{"<%= @trackid %>"}&player_type=tiny{widgetParams}">    </param>
  <param name="allowscriptaccess" value="always"></param>
  <param name="wmode" value="transparent"></param>
  <embed wmode="transparent" allowscriptaccess="always" height="18" width="100%"     src="https://player.soundcloud.com/player.swf?    url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F{trackId}&player_type=tiny{widgetParams}">    </embed>
</object> 
</div>

To change the {trackid} im using the value of the track.id, which i get in the controller with this code

 client = Soundcloud.new(:client_id => '2074955755d1c3997e10463d8a56960f')

# call the resolve endpoint with a track url
track = client.get('/resolve', :url => "http://soundcloud.com/forss/flickermood")

# print the track id
@trackid = track.id

This is not working.

Another way I tried to make this work is trough the oEmbed. I tried to run the example in the API documentation.

In the View file I understand I have to put the Javascript Widget:

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
SC.initialize({
  client_id: 'xxxxxxxxxxxxxxxxxxxxxxx'
});

var track_url = 'http://soundcloud.com/forss/flickermood';
SC.oEmbed(track_url, { auto_play: true }, function(oEmbed) {
  console.log('oEmbed response: ' + oEmbed);
});
</script>

And in the controller this code:

# create a client object with your app credentials
client = Soundcloud.new(:client_id => 'xxxxxxxxxxxxxxxxxxxx')

# get a tracks oembed data
track_url = 'http://soundcloud.com/forss/flickermood'
embed_info = client.get('/oembed', :url => track_url)

# print the html for the player widget
puts embed_info['html']

I´m a bit lost and I think im failing in some basic thing, and thats why I dont find info about how exactly implement this.

Thanks for your time

Upvotes: 0

Views: 1107

Answers (1)

halmeetdave
halmeetdave

Reputation: 356

This line in your view jumps out at me:

<param name="movie" value="https://player.soundcloud.com/player.swf?    url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F{"<%= @trackid %>"}&player_type=tiny{widgetParams}">    </param>

The double quotes around your @trackid are cutting off the value parameter and messing up your HTML. Try this then check the HTML your view generates:

<param name="movie" value="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F<%= @trackid %>&player_type=tiny{widgetParams}"></param>

Upvotes: 2

Related Questions