Having done a lot of research on the Wiki, studying the code in sc-player.js and some tests, I think I found a solution to your problem. Try the following:
First add this code to the sc-player.js immediately before the comment // the default Auto-Initialization (this line will be like 8 lines to the end of the file)
$.scPlayer.loadTrackInfoAndPlay=function($elem,track){ var playerObj=players[$elem.data('sc-player').id]; playerObj.tracks.push(track); var index =playerObj.tracks.length-1; var $list=$(playerObj.node).find('.sc-trackslist'); var $artworks=$(playerObj.node).find(".sc-artwork-list"); // add to playlist var $li=$('<li><a href="' + track.permalink_url +'">' + track.title + '</a><span class="sc-track-duration">' + timecode(track.duration) + '</span></li>') .data('sc-track', {id:index}) .appendTo($list); // add to artwork list $('<li></li>') .append(artworkImage(track, true)) .appendTo($artworks) .data('sc-track', track); $li.click(); }
The function above will take care of adding a new track to the playlist and start playing the track.
Now suppose you have this HTML for players
<h2>Top Player</h2> <div id="topPlayer"> <div class="sc-player"> <a href="http://soundcloud.com/matas/matas-petrikas-live-at-gravity-club-30-05-2008">My live track</a> <a href="http://soundcloud.com/matas/on-the-bridge">On the bridge</a> </div> </div> <h2>Small Player</h2> <div id="smallPlayer"> <a href="http://soundcloud.com/forss/sets/soulhack" class="sc-player">Soulhack</a> </div>
Be sure to wrap the sc-player in a div , preferably with id , so you can later refer to players in Javascript:
Finally, you can use this Javscript code to determine when a track is clicked in smallPlayer , and add and play this track in topPlayer
$(function(){ var $topPlayer=$("#topPlayer .sc-player");//Top player var $smallPlayer=$("#smallPlayer .sc-player");//Small Player $smallPlayer.on("onPlayerInit.scPlayer",function(evt){//When player is ready $smallPlayer.on("onPlayerTrackSwitch.scPlayer",function(evt,track){//Listen to track switch in smallPlayer setTimeout(function(){//Wait a bit, to avoid playing problems between both players $.scPlayer.loadTrackInfoAndPlay($topPlayer, track); },250); }); }); });
What is it!.
EDIT
If you only have the URL of the song you want to add, you can do the following:
First add this other function to the sc-player.js immediately after the previous loadTrackInfoAndPlay function:
$.scPlayer.loadTrackUrlAndPlay=function($elem,url){ var apiUrl = scApiUrl(url, apiKey); $.getJSON(apiUrl, function(data) { if(data.duration){ data.permalink_url = url; $.scPlayer.loadTrackInfoAndPlay($elem,data);
Now suppose you have this code for the song urls:
<p> The links <br /> <a class="songUrl" href="https://soundcloud.com/feintdnb/coldplay-fix-you-feint-bootleg">Coldplay-Fix you</a><br /> <a class="songUrl" href="https://soundcloud.com/nct-1/nct-you-preview-out-soon-for">NCT - You</a><br /> <a class="songUrl" href="https://soundcloud.com/tufftouch/devil-eyes-konflix-feat-leanne">Konflix - Devil Eyes</a> </p>
Then you can use this code to add the song to the playlist and start playing it (or just play it if it already exists)
$(".songUrl").click(function(event){ event.preventDefault(); var url=$(this).attr("href");
And all that is needed.