spotify_sdk 1.0.0
spotify_sdk: ^1.0.0

Flutter Android iOS web

A flutter plugin that let's you communicate with the spotify sdk and auth lib

spotify_sdk #

pub package Dry Run licence

Description #

This is a flutter package that wraps the native iOS and Android Spotify "remote" SDKs as well as the Spotify Web Playback SDK for web.

Installation #

To use this plugin, add spotify_sdk as a dependency in your pubspec.yaml file.

Setup #

Android #

This package is using both the spotify-app-remote sdk and spotify-auth library. The auth library is needed to get the authentication token to work with the web api.

From the Spotify Android SDK Quick Start. You need two things:

  1. Register your app in the spotify developer portal. You also need to create a sha-1 fingerprint and add this and your package name to the app settings on the dashboard as well as a redirect url.
  2. download the current Spotify Android SDK. Here you need the spotify-app-remote-.aar and spotify-auth-.aar.

After you are all setup you need to add the *.aar files to your Android Project as Modules. See the Spotify Android SDK Quick Start for detailed information.

Important here is the naming so that the package can find the modules.

  • Remote: spotify-app-remote
  • Auth: spotify-auth

iOS #

Register your app in the spotify developer portal. You also need to register your Bundle ID as well as a Redirect URI.

Follow the instructions in the section Setup the iOS SDK of Spotify iOS SDK Quick Start.

Web #

  1. Register your app in the spotify developer portal. You need to provide a redirect URL which points to a dedicated page on a website you own.

  2. Paste the following onto the webpage, which you linked to in your redirect URL.

<!DOCTYPE html>
<html>
  <head>
    <title>Authenticating Spotify</title>
  </head>
  <body>
	<p>Please wait while we authenticate Spotify...</p>
	<script type="text/javascript">
		if(window.opener) {
			window.opener.postMessage('?' + window.location.href.split('?')[1], "*");
		} else {
			window.close();
		}
	</script>
  </body>
</html>

You need Spotify Premium to access the Web SDK.

Usage #

To start using this package you first have to connect to Spotify. To only connect you can do this with connectToSpotifyRemote(...) or getAuthenticationToken(...) in both of these methods you need the client id, given in the spotify dashboard and the redirect url you set in the settings on the dashboard. You can also optionally pass an accessToken and on iOS it avoids having to switch to the Spotify app for establishing the connection.

  await SpotifySdk.connectToSpotifyRemote(clientId: "", redirectUrl: "")

If you want to use the web api as well you have to use this method to get the authentication token. You can specify multiple scopes by separating them with a comma "," as shown below. For more information on scopes you can refer to Spotify Authorization Scopes Guide

  var authenticationToken = await SpotifySdk.getAuthenticationToken(clientId: "", redirectUrl: "", scope: "app-remote-control,user-modify-playback-state,playlist-read-private");

Have a look in the example for detailed insights on how you can use this package.

Api #

Connecting/Authenticating

FunctionDescriptionAndroidiOSWeb
connectToSpotifyRemoteConnects the App to Spotify
getAuthenticationTokenGets the Authentication Token that you can use to work with the Web Api
disconnectdisconnects the app connection

Player Api

FunctionDescriptionAndroidiOSWeb
getPlayerStateGets the current player state
pausePauses the current track
playPlays the given spotifyUri
queueQueues given spotifyUri
resumeResumes the current track
skipNextSkips to next track
skipPreviousSkips to previous track
seekToSeeks the current track to the given position in milliseconds🚧
seekToRelativePositionAdds to the current position of the track the given milliseconds🚧
subscribeToPlayerContextSubscribes to the current player context
subscribeToPlayerStateSubscribes to the current player state
getCrossfadeStateGets the current crossfade state
toggleShuffleCycles through the shuffle modes
setShuffleSet the shuffle mode
toggleRepeatCycles through the repeat modes
setRepeatModeSet the repeat mode

Images Api

FunctionDescriptionAndroidiOSWeb
getImageGet the image from the given spotifyUri🚧

User Api

FunctionDescriptionAndroidiOSWeb
addToLibraryAdds the given spotifyUri to the users library🚧
getCapabilitiesGets the current users capabilities🚧🚧
getLibraryStateGets the current library state🚧🚧
removeFromLibraryRemoves the given spotifyUri to the users library🚧
subscribeToCapabilitiesSubscribes to the current users capabilities🚧🚧
subscribeToUserStatusSubscrives to the current users status🚧🚧

Connect Api

FunctionDescriptionAndroidiOSWeb
connectSwitchToLocalDeviceSwitch to play music on this (local) device🚧🚧🚧

Content Api

FunctionDescriptionAndroidiOSWeb
getChildrenOfItemtbd🚧🚧🚧
getRecommendedContentItemstbd🚧🚧🚧
playContentItemtbd🚧🚧🚧

Official Spotify Docs #

30
likes
90
pub points
79%
popularity

A flutter plugin that let's you communicate with the spotify sdk and auth lib

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

tobiasbusch90@gmail.com

License

MIT (LICENSE)

Dependencies

crypto, dio, flutter, flutter_web_plugins, js, json_annotation, logger

More

Packages that depend on spotify_sdk