This plugin included all main functions of audio player for Spotify servise 😏
To communicate with Spotify you need to register your application’s id in the Developer Portal. This value is used to authenticate your application against Spotify client.
You may install latest version from master
cordova plugin add https://github.com/adnotam/cordova-plugin-spotify
cordova plugin rm cordova-plugin-spotify
- Android
- iOS
setVolume()
and event onVolumeChanged()
It will be fixed when this methods will be in Spotify SDK
You must have premium account from Spotify service for playing music ❗
After device is ready you must defined the main variable:
var Spotify = window.cordova.plugins.SpotifyPlugin;
👍 After this you may use all method in your code.
All methods returning promises, but you can also use standard callback functions.
Spotify.auth(success, error, token, clientId);
- success - success callback
- error - error callback
- token - spotify access token;
- clientId - your application id in Spotify.
Spotify.getPosition(success, error);
- success - success callback
- error - error callback
Spotify.getToken(success, error);
- success - success callback
- error - error callback
Spotify.loadFeaturedPlaylists (success, error, token);
- success - success callback
- error - error callback
- token - access token
Spotify.loadFeaturedPlaylistTracks (success, error, id, token);
- success - success callback
- error - error callback
- id - Featured Playlist's ID
- token - access token
Spotify.loadUserAlbums (success, error, token);
- success - success callback
- error - error callback
- token - access token
Spotify.loadUserAlbumTracks (success, error, id, token);
- success - success callback
- error - error callback
- id - User album's ID
- token - access token
Spotify.loadUserPlaylists (success, error, token);
- success - success callback
- error - error callback
- token - access token
Spotify.loadUserPlaylistTracks (success, error, id, token);
- success - success callback
- error - error callback
- id - User Playlist's ID
- token - access token
Spotify.login(success, error, appId, redirectURL, mode);
- success - success callback
- error - error callback
- appId - your application id in Spotify
- redirectURL - White-listed addresses to redirect to after authentication success OR failure
- mode - The mode of debugging, if you use Xcode emulator its value should be "debug" else empty string
Spotify.logout();
Spotify.next();
Spotify.pause(error);
- error - error callback
Spotify.play(success, error, value);
- success - success callback
- error - error callback
- value - track id or album id or playlist id
Example:
> Spotify.play(success, error, "spotify:track:3qRNQHagYiiDLdWMSOkPGG");
> Spotify.play(success, error, "spotify:album:75Sgdm3seM5KXkEd46vaDb");
> Spotify.play(success, error, "spotify:user:spotify:playlist:2yLXxKhhziG2xzy7eyD4TD");
Spotify.prev();
Spotify.resume();
Spotify.seek(position);
position - value between 0...100 %
Spotify.seekTo(error, position);
- error - error callback position - value in seconds
Spotify.Events.onConnectionMessage = function(args){};
args[0] - message;
Spotify.Events.onLoggedIn = function(args){};
args[0] - access token;
Spotify.Events.onLoggedOut = function(){};
Spotify.Events.onLoginFailed = function(args){};
args[0] - error code;
Spotify.Events.onLoginResponse = function(args){};
args[0] - response type;
Spotify.Events.onPlayback.AudioFlush = function(args){};
args[0] - position (ms);
Spotify.Events.onPlayback.BecameActive = function(){};
Spotify.Events.onPlayback.BecameInactive = function(){};
Spotify.Events.onPlayback.ContextChanged = function(args){};
args[0] - position (ms);
Spotify.Events.onPlayback.DeliveryDone = function(){};
Spotify.Events.onPlayback.Error = function(args){};
args[0] - error message
Spotify.Events.onPlayback.LostPermission = function(){};
Spotify.Events.onPlayback.MetadataChanged = function(args){};
args[0] - current track name args[1] - artist name args[2] - album name args[3] - track duration (ms)
Spotify.Events.onPlayback.Next = function(args){};
Spotify.Events.onPlayback.Pause = function(){};
Spotify.Events.onPlayback.Play = function(){};
Spotify.Events.onPlayback.Position = function(args){};
args[0] - position (ms)
Spotify.Events.onPlayback.Prev = function(){};
Spotify.Events.onPlayback.RepeatOff = function(){};
Spotify.Events.onPlayback.RepeatOn = function(){};
Spotify.Events.onPlayback.ShuffleOff = function(){};
Spotify.Events.onPlayback.ShuffleOn = function(){};
Spotify.Events.onPlayback.TrackChanged = function(){};
Spotify.Events.onPlayback.TrackDelivered = function(){};
Spotify.Events.onSuccess = function(){};
Spotify.Events.onTemporaryError = function(){};
- Aleksey Stepanets
- Antonio Facciolo