Player creation options
Create method
create is the only public method of OfficialFM.Player. It takes a 'options hash', which is described
in the next sections. Here's a simple example of track player:
var player = OfficialFM.Player.create({
container_id: 'player_container',
type: 'track',
id: 7137
});
Mandatory options
Those three options must be present in any call to create
| container_id | id of the container. ex : 'player_container' |
| type | either 'track' or 'playlist' |
| id | ID of a track or a playlist (depending on the player's type) |
Optional options
| aspect | aspect of player. values: large, standard, artwork, small, mini |
|---|
| width | string or number : width of player in pixel or %. (valid only for artwork & small players). ex : '300', '60%' |
Event listeners
These options register callbacks. They're used like so:
var player = OfficialFM.Player.create({
container_id: 'player_container',
type: 'track',
id: 7137,
onProgress: function (progress) {
console.log('Progress: ' + progress.played_seconds + ' / ' + progress.total);
}
});
| name | callback prototype | description |
| onReady | function () | Called when player is ready to play. |
|---|
| onPlay | function (track_id) | Called when a track starts playing |
|---|
| onPause | function () | Called when a track is being paused |
|---|
| onProgress | function (progress) | Progress has fields {played_seconds, played_percent, total}. Called twice per second minimum. |
|---|
| onChangeTrack | function (track_id) | Called when player switches to another track |
|---|
| onChangeTracklist | function () | Called when player switches to another tracklist |
|---|
| onTracklistEnd | function () | Called when tracklist's end is reached |
|