voronianski / soundcloud-audio.js

:musical_note: SoundCloud tracks and playlists with HTML5 Audio API
http://caniuse.com/#feat=audio
284 stars 46 forks source link

Support Secret Tracks #4

Closed npbee closed 8 years ago

npbee commented 8 years ago

Hello! I had a use case for working with "secret" Soundcloud tracks. In the case of "secret" Soundcloud tracks, the stream urls are given with a secret_token query param, e.g.:

https://api.soundcloud.com/tracks/xxxxx/stream?secret_token=xxxx

The play function previously just appended `?client_id=...' to the end of the stream URL for the track, so the resulting URL was incorrect:

https://api.soundcloud.com/tracks/xxxxx/stream?secret_token=xxxx?client_id=...

I defined a simple helper function for appending query params to a url that checks to see if there is already any params defined. This is currenly only in use on the play function because that was my specific use case, but there look to be some other parts of the code that could use it.

It was a little tricky to test because this would only throw an error when the audio element attempted to play the src with the incorrect URL, but let me know if you have any suggestions.

Thanks!

voronianski commented 8 years ago

@npbee thanks, that's useful :+1: