I'm currently using http://ifttt.com to grab my public favourites from SoundCloud and post them to my Wordpress site (http://diversesounds.co.uk).
IFTTT creates a post on my site with the following contents;
<div class="trackUrl" id="(IFTTT then grabs the Track URL and places it here)">
I then have the following block of JS;
<script src="//connect.soundcloud.com/sdk.js"></script>
<script>
<?php
if(have_posts()): while (have_posts()) : the_post(); ?>
<?php
// Exploding the content to get track url from Div ID
$theContent = get_the_content();
$explode = explode('"', $theContent);
$trackUrl = $explode[3];
?>
SC.oEmbed(
"<?php echo $trackUrl; ?>",
{
color: "494e72",
show_comments: false
},
document.getElementById("<?php echo $trackUrl; ?>")
);
<?php endwhile; endif; ?>
The above code works perfectly but what I would like it to do is autoplay the next track after finishing the first manually played track.
You could add a listener for the onMediaEnd event and try to play the next track with that:
soundcloud.addEventListener('onMediaEnd', function(player, data) {
// find the next player here and use the API method api_play()
});
Docs: http://developers.soundcloud.com/docs/widget#widget-events
You'll probably need to swap out the embed method though. Their JS wrapper is on GitHub
Please refer to the HTML5 Widget API documentation.
You could attach event handlers to FINISH
events. However, my recommendation would be to use a different approach and go with Audio5JS, SoundCloud's own JS SDK or kilokeith/soundcloud-soundmanager-player. You could then build UI yourself and play all the music with player.
The difference is that each widget is quite a complex single-page JS application and is not really intended for the purpose you are trying to use it for.
UPD. example flow (just out of my head):
collect references to all widget iframes by DOM class
store them in array `widgets`
initialise API wrapper with first element of that array `SC.Widget(widgets[0])`
attach event handler `finishHandler` to `FINISH` event
`finishHandler` needs to
initialise API wrapper `SC.Widget(widgets[1])` and start playback with this new widget
attach the same `finishHandler` to `FINISH` event of the newly initialised widget
shift first widget from the array `widgets.shift()`
This is probably too simple and naive. But maybe it'll still help you.