ReferenceMedia
SoundCloudAudio
Audio component that plays SoundCloud tracks and sets through the SoundCloud Widget
The SoundCloud Widget plays public and private SoundCloud tracks and sets. This component drives the widget and reports its state like a native <audio> element, so a player skin can control it.
Import
Load a source
src takes any of these SoundCloud URLs:
- A track:
soundcloud.com/<user>/<track> - A set:
soundcloud.com/<user>/sets/<set> - A private track or set, with its secret token:
soundcloud.com/<user>/<track>/s-<token> - An API resource:
api.soundcloud.com/tracks/<id>orapi.soundcloud.com/playlists/<id>, with an optionalsecret_token. The id can also be a URN such assoundcloud:tracks:<id> - A widget embed URL:
w.soundcloud.com/player/?url=..., as SoundCloud’s own embed code gives it
m.soundcloud.com links work too. Add #t= to start at a given time, in seconds (#t=90), clock time (#t=1:30), or units (#t=1m30s). Profiles, likes, and other pages that list sounds are not supported.
Controls
The widget is the only UI SoundCloud offers, so controls decides whether the component is visible at all. Without controls, the component hides itself and plays as an invisible transport: a hidden iframe still loads and plays, so a player skin drives playback while the widget takes no room on the page.
With controls, the component shows the widget, and the audio skin draws its controls below it, so the two do not overlap. Anything the listener does in the widget shows in the skin: play, pause, seeking on the waveform, and picking another track of a set. The widget is also the part of the page that credits the uploader and links back to the sound on SoundCloud (see SoundCloud’s terms of use).
With controls, the component is 166 pixels tall by default, SoundCloud’s classic layout. Set a height to change it. From about 300 pixels, a set also shows its track list, and 450 pixels shows most of it. The large artwork layout of visual: true (see widget parameters) needs 300 pixels or more. At the default height, the artwork shows only behind the waveform.
Widget parameters
By default, the component hides the parts of the widget a skin has no use for: the buy, share, and download buttons, comments, reposts, the teaser, the related tracks shown after a track ends, and the large artwork layout. The uploader, the title, the artwork, and the SoundCloud logo stay whenever the widget shows.
Change any of these, or set color, under source.engine.soundcloud, spelled as SoundCloud spells them:
Engine options win over the parameters of a widget embed URL, which win over the defaults. Set an option to null to drop a default.
Behavior
- A set plays as one source. When the widget moves on to the next track,
durationchanges,currentTimestarts again from0, anddurationchangefires.endedfires only after the last track.play()after the end starts the set again from its first track. loopreplays the track, or the set from its first track. If the widget does not start again,endedstill fires.- Volume and mute both work. The widget has no separate mute, so muting sets its volume to
0and unmuting restores the previous level. Mute applies before autoplay starts, so a muted autoplay starts muted. autoplaystarts playback once the widget is ready. Browsers can still refuse it, as they do for any embed. The widget’s ownauto_playparameter does the same and is never written to the widget URL, so the volume always applies first.bufferedis the stretch the widget reports as loaded, from where playback last started or landed.- The widget does not support playback rate, picture-in-picture, fullscreen, or text tracks, so the component offers none of them, and a player skin hides those controls.
preload,playsinline, andposterare accepted for parity with<audio>but have no effect.- A track that is private without its secret token, removed, or not available in the listener’s region reports a
MEDIA_ERR_SRC_NOT_SUPPORTEDerror, and so does a URL the component does not recognize. A widget that has not finished loading after 5 seconds reports aMEDIA_ERR_NETWORKerror. An error the widget reports during playback fires a non-fatalerrorevent but leaveserrorempty, because a set moves on to its next track by itself.
SoundCloud’s terms of use
The widget is covered by the SoundCloud Terms of Use, in the section about players and widgets. Without written consent from SoundCloud, you may not use the widget to:
- Aggregate SoundCloud content into a separate destination that substantially replicates what SoundCloud offers, or into a content service where SoundCloud content is a material part.
- Embed content on a site dedicated to one artist, unless the content is yours and you are that artist or represent them, or on a site dedicated to one genre.
These limits apply to commercial and non-commercial use. You also may not use the widget in a way that suggests that SoundCloud, an artist, or anyone else endorses or supports your site. SoundCloud can block your use of the widget at any time, for any reason.
The SoundCloud API terms, which ask you to credit the uploader and SoundCloud with links back to the sound, apply when you use the SoundCloud API, for example to play stream URLs in a player of your own. This component uses the widget, which SoundCloud says handles that credit itself. The widget gives that credit only while it shows, which is with controls. Without controls, we recommend that your page give the credit itself: name the uploader, name SoundCloud as the source, and link to the sound on SoundCloud. The Terms of Use also say you must not remove trademark, copyright, or other proprietary or legal notices that appear on content from SoundCloud.
Privacy
The widget loads from SoundCloud as soon as the component renders. The SoundCloud Privacy Policy says that SoundCloud may receive personal data when a visitor opens a page with an embedded widget, including which site they are on, and may recognize the visitor. The widget also stores data in the visitor’s browser. SoundCloud does not document an embed mode that avoids this, so if your site needs consent before it loads third-party content, render the component only after the visitor agrees.
Examples
Basic Usage
API Reference
Props
Accepts these Video.js-specific props:
Engine options
source.engine.soundcloud
Pass SoundCloud Widget parameters under source.engine.soundcloud, spelled exactly as SoundCloud spells them, plus anything SoundCloud adds next. Media Sources covers how engine options fit into a structured source.
The sound comes from src, so url has no engine.soundcloud spelling. referrerPolicy sets the referrerpolicy of the widget iframe rather than a widget parameter.
Refs
ref
Forwards to the rendered <iframe>,
an HTMLIFrameElement. The <iframe> cannot play or seek; use mediaRef for playback.
mediaRef
Receives the SoundCloudAdapter that
drives the embed, which exposes media methods and properties such
as play() and currentTime. It is set once the
adapter has attached to the <iframe>, so its target is already that element, and
it is cleared when the element unmounts.
Events
Handle standard media events with React event props such as onPlay and onTimeUpdate. The adapter dispatches them, not the <iframe>. For events without a React prop, call addEventListener on the adapter from mediaRef.