-
Notifications
You must be signed in to change notification settings - Fork 12
API
- Methods
- Properties
- Methods
- audioPlayer.login
- audioPlayer.addEventListener
- audioPlayer.removeEventListener
- audioPlayer.playURI
- audioPlayer.seekToOffset
- audioPlayer.getIsPlaying
- audioPlayer.setIsPlaying
- audioPlayer.getVolume
- audioPlayer.setVolume
- audioPlayer.getLoggedIn
- audioPlayer.getCurrentTrack
- audioPlayer.getCurrentPlaybackPosition
- Events
- Methods
- Properties
- Properties
- Properties
- Properties
- Properties
Authenticate the user with the Spotify API
spotify.authenticate(clientId, tokenExchangeURL, [scopes], callback)the clientId supplied by Spotify.
The URL for your token exchange service. See setting up a token exchange service
Custom scopes to request from the Spotify authentication service
The callback gets two arguments error and session. session is a spotify.Session object.
Search albums, artists or tracks. Return a maximum of 20 items. Use multiple requests with offset to receive more results.
spotify.search(query, searchType, [offset], session, callback)The query to search for.
this can be one of three strings:
-
artiststo perform an artist search. -
albumsto perform an album search. -
tracksto perform a track search.
The starting index of the search results. If omitted the search will start from the first entry.
The spotify.Session object belong to the user.
The callback gets two arguments error and result. The result object can have any of the following properties: artists, albums or tracks. These properties hold an array of objects with partial information compared to the 'full' Spotify objects spotify.Artist, spotify.Album and spotify.Track.
Request a Spotify object by their Spotify URI.
spotify.requestItemAtURI(uri, session, callback)The Spotify URI of the object that is being requested.
The spotify.Session object belong to the user. Only required for playlist URIs.
The callback gets two arguments error and object. object is the resulting data object belonging to the Spotify URI. See the description about Album, Artist, Track and Playlist for more information.
Get an array of playlists for user with username.
spotify.getPlaylistsForUser(username, session, callback);The username of the user to request the playlists from.
The spotify.Session object belong to the user.
The callback gets two arguments error and result. result is an array of partial items, see spotify.search for an explanation of partial items.
Create a new playlist on the user's account.
spotify.createPlaylist(name, session, callback);The name of the new playlist
The spotify.Session object belong to the user.
The callback gets two arguments error and playlist. playlist is a spotify.Playlist object that can be used for further modification of the playlist.
Normally a spotify.Session object is returned from spotify.authenticate() but you can use the spotify.Session object to store the session for later use. A session is valid for 24 hours after which the user will need to login again.
var session = new spotify.Session({username: 'someUsername', credential: 'AFD42....GD43'});The username of the user.
An access token to verify the session.
Create a new spotify.AudioPlayer object.
new spotify.AudioPlayer(companyName, appName)Your company name
Your application name
Registers the audio player with the Spotify service to allow playing tracks.
audioPlayer.login(session, [callback])The spotify.Session object belong to the user.
The callback gets a single argument error if an error occurred while logging in.
This example shows how to construct a spotify.AudioPlayer, login and play a track using the callback method.
var audioPlayer = new spotify.AudioPlayer('Your-Company-Name', 'Your-App-Name');
audioPlayer.login(session, function(error) {
audioPlayer.playURI('spotify:track:6JEK0CvvjDjjMUBFoXShNZ');
});Alternatively, you can also listen for the login event to start playback.
var audioPlayer = new spotify.AudioPlayer('Your-Company-Name', 'Your-App-Name');
var loginListener = function() {
audioPlayer.removeEventListener('login', loginListener);
audioplayer.playURI('spotify:track:6JEK0CvvjDjjMUBFoXShNZ');
}
audioPlayer.addEventListener('login', loginListener);
audioPlayer.login(session);Add an event listener to the audio player.
audioPlayer.addEventListener(event, listener)
audioPlayer.on(event, listener)The event linked to the event listener.
When an event is dispatched, the listener gets called with a zero or more arguments. See events for more information.
Remove an event listener to the audio player.
audioPlayer.removeEventListener(event, listener)The event linked to the event listener.
The listener that will be removed from the listener stack.
Add an event and remove it.
var logoutListener = function() {
console.log('AudioPlayer has logged out');
}
audioPlayer.on('logout', logoutListener);
// ....
audioPlayer.removeEventListener('logout', logoutListener);Play the audio track belonging to the supplied Spotify URI.
audioPlayer.playURI(uri, callback)The URI belonging to the track to play.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Skip the track to the specified offset.
audioPlayer.seekToOffset(offset, callback)The new playback position (offset) in milliseconds.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Request the current playback status.
audioPlayer.getIsPlaying(callback)The callback gets two arguments error and playing. The playing value will be a boolean.
Set the current playback status. This can be seen as a method for pausing / resuming playback.
audioPlayer.setIsPlaying(status, callback)The new playback status.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Request the playback volume.
audioPlayer.getVolume(callback)The callback gets two arguments error and volume. The volume value will be a numeric value between 0.0 and 1.0.
Set the playback volume.
audioPlayer.setVolume(volume, callback)The new playback volume between 0.0 and 1.0.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Request the current login status of the audio player.
audioPlayer.getLoggedIn(callback)The callback gets one argument result. The result argument will be a boolean.
Request information about the track that is currently playing.
audioPlayer.getCurrentTrack(callback)The callback gets two arguments error and track. The track value will be an object literal with the track's metadata.
Request the current playback position.
audioPlayer.getCurrentPlaybackPosition(callback)The callback gets two arguments error and offset. The offset value will be a numeric value in milliseconds between 0 and the duration of the track.
This event is dispatched when the player has logged in.
This event is dispatched when the player is logged out.
This event is dispatched when the playback permission is lost. This happens mostly when the user plays a track on another device.
This event is dispatched whenever an error occurs in the audio player.
The listener method receives a single string argument error.
If no error event listener is found, the AudioPlayer will throw a JavaScript Error.
This event is dispatched when a message is sent by Spotify to the user. This message has to be shown to the user see the iOS SDK reference.
The listener method receives a single string argument message.
If no message event listener is found, the AudioPlayer will fire a standard JavaScript alert.
This event is dispatched when the playback status has changed.
The listener method receives a single boolean argument status.
This event is dispatched if the playback offset has changed "unnaturally".
The listener method receives a single integer argument offset in milliseconds.
A playlist on the spotify service.
Change the playlist's name.
playlist.setName(name, session, callback)The name of the playlist
The user's spotify.Session object.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Change the playlist's description.
playlist.setDescription(description, session, callback)The playlist description
The user's spotify.Session object.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Change the collaborative flag.
playlist.setCollaborative(collaborative, session, callback)If the playlist should be collaborative.
The user's spotify.Session object.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Add tracks to the playlist.
playlist.addTracks(tracks, session, callback)An array of track Spotify URIs.
The user's spotify.Session object.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Permanently delete the playlist.
playlist.delete(session, callback)The spotify.Session object belong to the user.
The callback gets one argument error. The error argument will be null if successful or an Error object if something went wrong.
Name of the playlist
A numeric value showing the version of the playlist. Higher value equals newer version.
The Playlist's Spotify URI.
Defines if the playlist is a collaborative playlist.
The username of the user that created the playlist.
An array of partial track objects holding the track's name and uri.
The date and time when the playlist was last modified.
An album on the Spotify service.
The name of the album.
The Spotify URI belonging to the album.
The Spotify sharing URL (e.g., http://open.spotify.com/album/2bOPMrFFQ00pA4QzaBn16F)
External IDs belonging to the album, like the UPC code.
A list of ISO 3166 country codes.
A list of objects containing the name and uri (Spotify URI) of the artists belonging to the album.
A list of objects containing the name and uri (Spotify URI) of the tracks on the album.
Holds the properties year, month and day.
The type of album. Possible values:
albumsinglecompilationappearsOn
A list of genres belonging to the album.
A list of spotify.Image objects.
The largest cover image.
The smallest cover image.
A numeric value between 0.0 and 100.0, expressing the album's popularity.
An artist on the Spotify service.
The name of the artist.
The Spotify URI belonging to the artist.
The Spotify sharing URL (e.g., http://open.spotify.com/artist/0gxyHStUsqpMadRV0Di1Qt)
A list of genres belonging to the artist.
A list of spotify.Image objects.
The smallest artist image.
The largest artist image.
A numeric value between 0.0 and 100.0, expressing the artist's popularity.
A Spotify audio track.
The name of the track.
The Spotify URI belonging to the track.
The Spotify sharing URL (e.g., http://open.spotify.com/track/0bhCFkDynlihxlkI1nd4WZ)
The URL of the track's preview mp3.
The duration of the track in seconds.
A list of objects containing the name and uri (Spotify URI) of the artists belonging to the track.
A partial object with holding the name and uri (Spotify URI) of the album where the track belongs to.
The track's position on the disc.
The disc number of the track.
A numeric value between 0.0 and 100.0, expressing the track's popularity.
Value showing if the track has been flagged as explicit.
External IDs belonging to the album, like the UPC code.
A list of ISO 3166 country codes.
An image belonging to an artist or album.
The URL of the image.
The image width (pixels)
The image height (pixels)