Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I access a SoundCloud public stream?

Tags:

url

soundcloud

How do I play a track from a SoundCloud URL, which, for example, I got from the xml response from a query

<stream-url>https://api.soundcloud.com/tracks/31164607/stream</stream-url>

I should have thought that it would have been as easy as:

https://api.soundcloud.com/tracks/31164607/stream&client_id=my_client_id

yet I get

<error>401 - Unauthorized</error>

All I want to do is consume it in a Silverlight MediaElement, so all I need is set some url to the MediaElement's Source property.

I've checked an application that I wrote about 2 years ago, and THEN, accessing the stream url was as easy as this for a public track:

http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY

however this no longer seems to work.

For example, all I had to do then in C# was:

MediaElement me = new MediaElement();
me.Source= new Url("http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY");
me.Play();

Any hints would be appreciated.

I had a reply on a Microsoft forum that seems to imply that SoundCloud might not be possible to stream to Windows 8 Metro devices without consuming the whole stream before playback starts - which is quite worrying and would seem to imply that to make authentication possible, it would have to be done entirely in the url querystring insterad of using the header:

(The following reply is the answer to the following question: 'I am able to access an audio stream by http using the MediaElement, however I need to access it via https in which I need to add the oAuth info to the header of the initial request. How is this done when using a MediaElement, and if it cannot be done, what is the workaround for consuming an audio feed in Metro 8 that requires header authentication to stream?')

"Direct access to the underlying network stream is not currently permitted by the MediaElement. Because of this there is currently no way to modify the header of the HTTP request to include any additional authentication information. That said, you do have control over the URL. You could theoretically setup an HTTP proxy service that translated the HTTP GET request parameters into the necessary oAuth credentials. Keep in mind that this is just a theoretical workaround. You may find different behavior in practice. Another theoretical workaround would be to handle the oAuth yourself via a raw stream socket and pass the retuned media data to the MediaElement via "Set Source" and a "Random Access Stream". Please keep in mind that this method has major limitations. in order to use a "Random Access Stream" with the ME you need to make sure all of the data is available before passing it to the ME."

The proxy service is not scalable for an application that is merely distributed for free as every stream would need to come via the proxy. And the raw stream socket, although getting around this, would mean that playback could not start until the whole file had downloaded - and this goes against all current UX (User Experience) guidelines.

So once again, if anyone has any tips, or info about how the whole authentication thing can be achieved in a querystring instead of using headers, I'd appreciate it!

like image 744
Red XQuirrel Avatar asked Dec 07 '22 13:12

Red XQuirrel


1 Answers

I'm a little confused about whether you're referring to a public or a private track? If it's a public track, then you shouldn't need to send any authentication information, just your client id.

When I request https://api.soundcloud.com/tracks/31164607/stream?client_id=YOUR_CLIENT_ID then I get a 302 redirect to the proper mp3 stream.

like image 199
nickf Avatar answered Jan 01 '23 21:01

nickf