I am using soundcloud custom player to create a player which can play all the songs on my site. This works pretty good when i just place static url of any track or a post. But what i want is to add the song to the list dynamically.
I have done lots of research but couldn't get it to work. What i want is there would be multiple players through out the site. kind of(http://soundcloud.com) and there would a main player on the top(like soundcloud) which would play around 100 latest songs on site and there would be a smaller player clicking on which will just append that song to the list and start playing that song.
I am not sure if this is the right process. If any one can just give me any hint how i can proceed further then it would be great.
I'll try to give you as much info as I can, but as there's nowhere to start, I'm not sure if it will help. It's important to start with the wiki. This is what I could extract from there:
Dynamic Track Loading
The player can be created on the fly, and therefore any url can be added. In order to do that, the following methods are available:
Appending directly to the element:
or Create the object and append where you want:
A little example I just found:
I believe that should solve the dynamic track loading.
Initializing scPlayer
It's important to take into account that the scPlayer must load itself, and therefore will not work if you change the url directly with jQuery. In order to initialize the scPlayer, which takes place once the DOM has loaded, you can use
or
Default loading takes place, as I said, on DOM load with the following method
This default behaviour can be changed as follows:
That's what I've got up to now. Try to get the scPlayer working (loading songs dynamically) and we can follow with the data load and all that stuff.
After doing a lot of research in the Wiki, studying the code in
sc-player.js
, and some testing, I think I've found a solution to your problem. Try the following:First, add this code to
sc-player.js
file, just before the comment// the default Auto-Initialization
(this line is just like 8 lines before the end of the file)The function above, takes care of adding a new track to the playlist and starts playing the track.
Now, suppose you have this html code for the players
Make sure to wrap your
sc-player
s in adiv
, preferably with anid
, so you can reference the players later in Javascript:Finally, you can use this Javscript code to detect when a track is clicked in
smallPlayer
and add and play that track intopPlayer
And that's It!.
EDIT
If you only have the url of the song to be added, you can do the following:
First, add this other function to
sc-player.js
file, just after the previousloadTrackInfoAndPlay
function:Now, suppose you have this code for the urls of the songs:
Then, you can use this code to add the song to the playlist and start playing it (or just playing it if it already exists)
And that's all that is needed.