ILikeSongChooser
From iLike
The function call iLikeSongChooser() displays a song-chooser user interface, and returns a track ID based on the song that was selected by the user. The track ID can then be used when displaying songs using the iLikeDisplaySong method. The track id will be 0 if no song was selected. The track ID is returned using a callback which can either be passed to the function or a global function named iLikeSongSelected which you must implement. In addition to track ID, the song name and artist name are also returned to you as separate parameters to this callback.
Contents |
Parameters
- devKey - your developer key, unless set in the global variable _iLikeDevKey
- title - optional, the title for the song-chooser user interface, if you want something other than "Choose a song"
- okBtn - optional, the text for the OK button, if you want something other than "OK"
- cancelBtn - optional, the text for the Cancel button, if you want something other than "Cancel"
- onSelected - optional, the callback function to call instead of the global iLikeSongSelected
- searchString - optional, the initial search string, if not supplied the song chooser dialog will default to displaying some currently popular songs.
Callback function
After the user interacts with the song chooser, the callback function will be called, passing in the user's selection. You must implement this function, either by implementing a global iLikeSongSelected function or by passing an appropriate function in the onSelected parameter. The callback takes three parameters:
- trackId the ID of the track that was selected, or 0 if no song was selected (if the user clicked the Cancel button)
- songName the name of the song selected
- artistName the name of the artist
Example usage
Here is some sample code.
- Click to see this example in action in HTML/Javascript
- Click here to see this example in action on Facebook/FBML
<a href="#" onclick="iLikeSongChooser(); return false;">Choose song</a>
<div id="song2" />
<script>
// Called when the user selects a song
function iLikeSongSelected(trackId, songName, artistName) {
// Persist track id
var ajax = new Ajax();
var params = {trackId:trackId};
ajax.post("http://myserver.com/persist_track_id", params);
// Display selected song
iLikeDisplaySong({elId:"song2", trackIds:trackId});
}
</script>
This snippet shows the use of a dynamic callback and pre-selected initial search:
<a href="#" onclick="iLikeSongChooser({onSelected: myCallback, searchString: 'T. Rex'}); return false;">Choose song (with search string and custom callback)</a>
<div id="song2" />
<script>
// custom callback function
function myCallback(trackId, songName, artistName) {
// Display selected song
iLikeDisplaySong({elId:"song2", trackIds:trackId});
}
</script>
