The stream Url you retrieved from their API can't be directly used within your own audio player.
Because actually, the stream URL is not the end-point URL of the audio you are expecting to play. The actual audio (in mp3 format) of the tracks are being created 'on demand' when you send an http request to the stream url. (There is no such thing as the actual audio is waiting ready for you to be streamed anytime - they are stored as binaries in AWS blob storages)
Upon requesting the 'audio' with the unique stream URL, you are being redirected to the actual end-point with the audio- this is the physical path and you can play it directly within your audio player. This generated audio URL has an expiration time like 15-20 minutes.
To achieve what I am talking about here, you will have to do some tricks similar to this: (Code is in C# but you will get the idea)
public void Run()
{
if (!string.IsNullOrEmpty(TrackUrl))
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(TrackUrl + ".json?client_id=YOUR_CLIENT_ID");
request.Method = "HEAD";
request.AllowReadStreamBuffering = true;
request.AllowAutoRedirect = true;
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
}
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
this.AudioStreamEndPointUrl = myResponse.ResponseUri.AbsoluteUri;
this.SearchCompleted(this);
}
myResponse.Close();
}
The AudioStreamEndPointUrl
is the actual URL where your mp3 audio will reside for the next 15-20 mins. Note that each time you would like to stream a song, you will have to re-request the song via the first stream URL..
So it's not actually SoundCloud guys don't want you to stream the tracks in your custom audio player but it's rather related with the storage sense of the audio data. Keeping such data as blob rather than the actual mp3 file is perhaps cheaper for them.
Note that by doing this you should play fair and actually credit the SoundCloud somewhere in your application.