spotify_sdk 0.5.0 copy "spotify_sdk: ^0.5.0" to clipboard
spotify_sdk: ^0.5.0 copied to clipboard

outdated

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

spotify_sdk #

pub package Dry Run licence

Description #

This will be a spotify_sdk package for flutter 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.

Setup #

Android #

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

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) {
			var error = getParameterByName('error');
			if(error) {
				window.opener.postMessage('?' + error, "*");
			} else {
				window.opener.postMessage(window.location.hash, "*");
			}
		} else {
			window.close();
		}

		function getParameterByName(name, url) {
		    if (!url) url = window.location.href;
		    name = name.replace(/[\[\]]/g, '\\$&');
		    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
		        results = regex.exec(url);
		    if (!results) return null;
		    if (!results[2]) return '';
		    return decodeURIComponent(results[2].replace(/\+/g, ' '));
		}
	</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.

  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

Function Description Android iOS Web
connectToSpotifyRemote Connects the App to Spotify ✔️ 👷 ✔️
getAuthenticationToken Gets the Authentication Token that you can use to work with the Web Api ✔️ 👷 ✔️
logout logs the user out and disconnects the app connection ✔️ 👷 ✔️

Player Api

Function Description Android iOS Web
getCrossfadeState Gets the current crossfade state ✔️ 👷
getPlayerState Gets the current player state ✔️ 👷 ✔️
pause Pauses the current track ✔️ 👷 ✔️
play Plays the given spotifyUri ✔️ 👷 ✔️
queue Queues given spotifyUri ✔️ 👷 ✔️
resume Resumes the current track ✔️ 👷 ✔️
skipNext Skips to next track ✔️ 👷 ✔️
skipPrevious Skips to previous track ✔️ 👷 ✔️
seekTo Seeks the current track to the given position in milliseconds ✔️ 👷 👷
seekToRelativePosition Adds to the current position of the track the given milliseconds ✔️ 👷 👷
subscribeToPlayerContext Subscribes to the current player context ✔️ 👷 ✔️
subscribeToPlayerState Subscribes to the current player state ✔️ 👷 ✔️
getCrossfadeState Gets the current crossfade state ✔️ 👷
toggleShuffle Cycles through the shuffle modes ✔️ 👷 👷
toggleRepeat Cycles through the repeat modes ✔️ 👷 👷

Images Api

Function Description Android iOS Web
getImage Get the image from the given spotifyUri ✔️ 👷 👷

User Api

Function Description Android iOS Web
addToLibrary Adds the given spotifyUri to the users library ✔️ 👷 👷
getCapabilities Gets the current users capabilities ✔️ 👷 👷
getLibraryState Gets the current library state ✔️ 👷 👷
removeFromLibrary Removes the given spotifyUri to the users library ✔️ 👷 👷
subscribeToCapabilities Subscribes to the current users capabilities ✔️ 👷 👷
subscribeToUserStatus Subscrives to the current users status ✔️ 👷 👷

Connect Api

Function Description Android iOS Web
connectSwitchToLocalDevice Switch to play music on this (local) device 👷 👷 👷

Content Api

Function Description Android iOS Web
getChildrenOfItem tbd 👷 👷 👷
getRecommendedContentItems tbd 👷 👷 👷
playContentItem tbd 👷 👷 👷

Official Spotify Docs #

155
likes
40
pub points
91%
popularity

Publisher

verified publisherminimalme.de

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

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

dio, flutter, flutter_web_plugins, js, json_annotation, logger

More

Packages that depend on spotify_sdk