The track ID to stream. Pass undefined to stop/skip playback.
A PlayerState object with playback controls and state.
import { usePlayer } from "soundcloud-api-ts-next";
function Player({ trackId }: { trackId: number }) {
const { playing, progress, duration, toggle, seek } = usePlayer(trackId);
return (
<div>
<button onClick={toggle}>{playing ? "Pause" : "Play"}</button>
<span>{Math.round(progress)}s / {Math.round(duration)}s</span>
</div>
);
}
useTrack for fetching track metadata
Control audio playback for a SoundCloud track.
Fetches the stream URL and creates an
HTMLAudioElementinternally. Provides play/pause/toggle/seek controls and reactive progress/duration state.