Create a new Adaptr Player instance. This creates the player object, but it will not be useful until initialize is called to request available music from the Adaptr servers.
Credentials are validated in the initialize call, so no error will be thrown here if they are not valid.
The token value associated with your Adaptr app, provided via adaptr.com/dashboard
The secret value associated with your Adaptr app, provided via adatpr.com/dashboard
Retrieve an array of all the client-generated playlists that have been stored for the current user via saveClientPlaylist.
Retrieve a client-generated playlist that was previously saved on the adaptr servers with saveClientPlaylist.
id of a client-generated playlist previously saved via saveClientPlaylist
Persist a client-generated playlist. This method allows SDK users to persist collections of AudioFiles on the Adaptr servers for later retrieval.
note - this 'playlist' is distinct from the 'playlists' generated in the adaptr.com dashboard. These playlists are meant to be created by end-users of the application and are not (currently) sharable with other users.
client-side playlist to persist on adaptr servers
Retrieve a PageOfAudioFiles in the station with the given name. Note that the page offset is 0-based.
Retrieve a station with the given name, or null
name of a station available from getStations
Return available stations. This method will throw an exception if initialize has not been called or resolved successfully.
If you're willing to wait, you can use the promise returned from whenAvailable or initialize instead of polling this property.
stations available to the player for playback
Search through all available stations for songs similar to the provided query. This method sorts the results based on how similar they are to the query. Note that a non-empty query must be provided. Searches can be limited to a specific, station, and the number of results can be adjusted via the options.
simple text query that will run again song title, artist, album text
search options
Notify that the user did not like this song play.
a Play object, containing an AudioFile, that the user does not like
Mark the given song as a favorite, and store on adaptr servers.
audio file to mark as a favorite
Retrieve a page of audio files from the server that the user has favorited. The audio files are sorted by date they were favorited, with the most recently favorited files appearing first.
0-based page index to retrieve
number of audio files to return per page
Notify that the user 'likes' this song play.
a Play object, containing an AudioFile, that the user likes
Remove the 'favorite' status for the given audio file, and tell the adaptr servers.
Remove a previous 'like' or 'dislike' indicator for the given song play.
Remove a like or dislike indicator for a Play
Initialize the player instance by validating the credentials and retrieving a list of available Stations from the Adaptr servers. This method returns a Promise that will resolve to a Session with a list of Station objects or reject if the credentials are not valid or no music is available for the current user. The promise returned by this method must be resolved before the player can perform any playback.
Subsequent calls to this method will stop music playback and reinitialize the instance. If you just want access to the Session object, then use whenAvailable.
Modern browsers require audio to be initialized and started in response to a user-interaction event (such as a 'click' event handler). Calls to playStation or playAudioFiles will try to initialize audio, but if the first call to either method wasn't initiated in an event handler, audio initialization will fail. This method may be called while in an event handler to handle audio initialization before those play methods are called. The method doesn't return any values, and may be called repeatedly without affecting anything if audio is already initialized.
If the player has been initialized, then this returns the promise from that original call. If the player has not been initialized, then this method calls initialize and returns that value.
Stop any playback currently in progress and immediately start playing the given array of audio files. Playback will stop when all files have been played.
This call must either be made from a user-initiated event handler (like a 'click' event handler) or a call to initializeAudio must have previously been made to initialize audio playback.
audio files to play or append to the current playback queue
playback options
Stop any playback currently in progress and immediately start playing a preview clip of the given audio file.
This call must either be made from a user-initiated event handler (like a 'click' event handler) or a call to initializeAudio must have previously been made to initialize audio playback.
the audio file to play a preview of
Immediately begin playing songs in a Station with the given name.
This will stop any existing playback.
Available stations are returned via initialize or getStations or the 'stations' event.
Stop any playback currently in progress and queue up an array of audio
files for playback. If playImmediately
is true, then kick off playback
of the queue, otherwise, the player will remain idle.
audio files to play or append to the current playback queue
playback options
Stop any playback currently in progress and queue up an a preview of the given
audio file for playback. If playImmediately
is true, then kick off playback
of the sample, otherwise, the player will remain idle.
audio file to play a sample of
playback options
Tune to the given station and load the first song into memory for immediate playback with play.
This will stop any existing playback, unless the same station is currently being played.
Resume playback of the current station or queued audio files, or start playback after a call to prepareAudioFiles or prepareStation.
Mute or unmute the player. This differs from just using setVolume in that the volume before muting is saved, so unmuting returns to that original volume.
true to mute, false to unmute
Stop audio playback and empty out the play queue. Future calls to play will have no effect until playAudioFiles or playStation is called.
Generated using TypeDoc
A Player instance plays collections of audio files. The player can be instructed to play audio files from a station (Station) or a simple array of AudioFiles. Once provided with a station or array of audio files (via playStation or playAudioFiles), the player maintains an index into the collection and plays the files, one by one, until the end of the collection is reached. The player can pause and resume playback, skip past an audio file that is currently playing, restart playback of an audio file, and go back to a file that appears earlier in the provided collection.
A player instance requires
token
andsecret
values that are used to authenticate with the Adaptr servers and identify which playlists/stations should be made available to the player.initialize must be called before the player is useful in any way.
Stations are provided by the player upon initialization. A 'playlist', published via the Adaptr.com web dashboard, equates to a 'station' in the SDK.
Individual audio files for playback can be discovered by listing the contents of stations (fetchAudioFilesInStation) or by searching through all available audio files (searchAudioFiles).
The Player emits various events that can be subscribed to with on and once. Event handlers are passed an argument with details of the event (see the definition of Event here), and an optional data item related to the event (
event.data
). The following events are broadcast in the course of the player's existance: