Callam
Callam

Reputation: 1009

Spotify app - preview 10 seconds of track then skip

I'm making a Spotify app, which imports playlists, and then gives you the option of previewing the playlist, so you'd be able to press a play button, which would work through the playlist, playing 10 seconds of a track then skipping to the next

I've got the playlist integration sorted, but am struggling to know where to start on this preview button, any ideas?

EDIT:

Should have been more specific

I wanted to preview the last 30 seconds of a track, so would need to find the duration (which is where my problem lies) bring it back 30 seconds and then play 10 seconds before skipping

Upvotes: 0

Views: 908

Answers (1)

nanobar
nanobar

Reputation: 66325

Perhaps something like this or am I misunderstanding?

function onPlayButtonClick() {
  playTheTrack();
  setTimeOut(playNextTrack, 10000);
}

Or recursively:

function playTrack(trackNumber) {
    stopCurrentTrack();
    playThisTrack();

    setTimeOut(function() {
        playTrack(++trackNumber);
    }, 10000);
}

Upvotes: 1

Related Questions