Soundcloud API: how to play only a part of a track

2020-03-30 05:54发布

问题:

For an upcoming project I am investigating the possibility to play only a certain length (for example 20s) of a track, using the Soundcloud API.

Could anybody indicate me if that is possible, or should a different track with that limited length be created separately?

Many thanks ! Maarten (WebForDreams)

回答1:

There are a few ways you can do this. Are you going to be using the JavaScript SDK or the player widget? For the player widget, you can just use seekTo().

If you're using the JavaScript SDK you can use the setPosition() method:

SC.initialize({
  client_id: 'foo'
});
SC.whenStreamingReady(function() {
  var sound = SC.stream(52933447);
  sound.setPosition(2000); // position, measured in milliseconds
  sound.play();
});

If you want to stop at a particular point, you could use onPosition().

Hope that helps!



标签: soundcloud