I'm recreating a music-guessing game, and most of the functionality is working. The problem is that the available song preview URLs usually contain a roughly 30-second highlight from the middle of each track. I want every round to begin at the actual start of the song so it's more challenging. Is there a free API or another practical way to do this without downloading and hosting a large library of songs?
3 Answers
Setting the audio position is easy if the file actually contains the beginning of the song: set the element’s `currentTime` to `0` before calling `play()`. The limitation is the source file—if the API only returns a middle-of-song preview, changing `currentTime` cannot recover the missing intro.
If you’re using Spotify preview URLs, their API determines which 30-second segment is provided, and you can’t change that segment or seek back to 0:00. Full-track playback requires the Spotify SDK, user authentication, and playback through an eligible Spotify client. Otherwise, you’d need an audio source that legally provides the beginning of each track, such as licensed files or another service with suitable playback controls. There isn’t really a free, unrestricted option that gives you the start of every commercial song.
Look for a music provider whose license and API allow either full playback or previews with a selectable start time. Many free services only expose fixed highlight clips, so you’ll need to check both the technical documentation and the usage rights. An embedded video or streaming player may be an alternative, but those services often restrict seeking, extracting audio, or using playback as part of another game.
Right—the preview has to include the first part of the track in the first place. If the provider only supplies the standard middle excerpt, there’s no client-side setting that can turn it into a 0:00 preview.

That makes sense. I can obtain individual tracks, but downloading and storing the opening section for a large number of songs isn’t practical.