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_idid of the container. ex : 'player_container'
typeeither 'track' or 'playlist'
idID of a track or a playlist (depending on the player's type)

Optional options

aspectaspect of player. values: large, standard, artwork, small, mini
widthstring 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);
  }
});
            

namecallback prototypedescription
onReadyfunction ()Called when player is ready to play.
onPlayfunction (track_id)Called when a track starts playing
onPausefunction ()Called when a track is being paused
onProgressfunction (progress)Progress has fields
{played_seconds, played_percent, total}.
Called twice per second minimum.
onChangeTrackfunction (track_id)Called when player switches to another track
onChangeTracklistfunction ()Called when player switches to another tracklist
onTracklistEndfunction ()Called when tracklist's end is reached