lisovaccaro
lisovaccaro

Reputation: 33946

SetTimeout how to do it?

I want to make this code run after 20 seconds with setTimeout:

<script type="text/javascript">
   soundcloud.addEventListener('onPlayerReady', function(player, data) {
     player.api_play();
   });
</script>

The code works correctly alone but I don't know how to delay it. How can I do it?

Thanks

Upvotes: 1

Views: 328

Answers (2)

CarlosZ
CarlosZ

Reputation: 8669

This will delay the execution of player.api_play() after the onPlayerReady event is fired. The code by @alex will the delay registering of the handler for the onPlayerReady event.

<script type="text/javascript">
   soundcloud.addEventListener('onPlayerReady', function(player, data) {
     setTimeout(function(player) {
         player.api_play();
     }, 2000);
   });
</script>

Upvotes: 1

alex
alex

Reputation: 490143

setTimeout(function() {

   soundcloud.addEventListener('onPlayerReady', function(player, data) {
     player.api_play();
   });

}, 20000);

Upvotes: 2

Related Questions