npm install soundcloud-audio --save
const SoundCloudAudio = ;// create new instance of audio// clientId is optional but without it you cannot play tracks directly from SoundCloud APIconst scPlayer = 'YOUR_CLIENT_ID';// if you have a SoundCloud api stream url you can just play it like thatscPlayer;// OR if you want to play a NON-SoundCloud audioscPlayer;// OR if you need to load a SoundCloud track and resolve it's datascPlayer;// OR a SoundCloud playlist and resolve it's datascPlayer;
new SoundCloudAudio('YOUR_CLIENT_ID', 'YOUR_CUSTOM_API_URL')
Create an instance of SoundCloudAudio, internally uses HTML5
<audio> element which is available under audio property.
- first argument, client id string, is optional but it's needed if you plan to use SoundCloud API directly (you can get it here - https://developers.soundcloud.com).
- second argument, custom API url string, is also optional but it allows you to use SoundCloud API proxy to not expose your client ids in the browser
If you don't have SoundCloud
https://api.soundcloud.com/tracks/:id/stream) or you need track's metadata then this method is for you. Pass original track's or playlist's url as a first argument. Once data will be resolved without errors, callback function will receive it as plain object as the only argument.
Start playing track if it's not playing right now.
Returns a Promise and accepts
options.streamUrl- any audio streaming url string (e.g. SoundCloud track's
stream_url), if it's passed it will be the main playing source.
options.playlistIndex- number that specifies the position of the track to play in resolved SoundCloud playlist's
Preload track data without playing it.
preloadType- this attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
'none'- indicates that the audio should not be preloaded
'metadata'- indicates that only audio metadata (e.g. length) is fetched
'auto'- indicates that the whole audio file could be downloaded, even if the user is not expected to use it
- see more at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#Attributes
Pause playing audio.
Stop playing audio and rewind it to start.
Skip to the next track in playlist to play.
Returns a Promise and accepts
options.loop- boolean, if set to
truewill start at the beginning of a playlist after the last track.
Return to the previous track in playlist (returns a Promise).
Helper method for integrating with HTML
<progress> element and its' polyfills. It changes
audio.currentTime with regarding to the progress position. Just pass the DOM event that you received on progress click and all necessary computations will be done automagically.
Adjust the volume with a number between 0 and 1, 0 being not audible and 1 being full volume.
Set the progress of the song to a specific number of seconds.
Instance of raw
<audio> element. There are several useful properties like
seconds) or events you may want to listen with
addEventListener (the full list of of them at
SoundCloud track duration converted into
seconds in order to be in sync with
Shows the current state of the player, returns
false or source of a currently streaming track.
SoundCloudAudio provides shortcuts to subscribe or unsubscribe handler functions on native
audio events. The list of supported events can be accessed here - https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events.
var SoundCloudAudio = ;var scPlayer = 'YOUR_CLIENT_ID';scPlayer;scPlayer;scPlayer;
|3+ ✔||3.5+ ✔||9+ ✔||10+ ✔||3.1+ ✔|
Copyright (c) 2015 Dmitri Voronianski firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.