Giter VIP home page Giter VIP logo

spotify_sdk's Introduction

spotify_sdk

pub package build 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.

  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");

On iOS you can store the token that you get from getAuthenticationToken(...) and then pass it to connectToSpotifyRemote(...) during the next session. This will avoid having to switch to the Spotify app for establishing the connection. This library does not handle storing the token. It is up to you to persist it wherever you see fit. Keep in mind that this feature is currently quite buggy in the native iOS SDK and has many side effects like random disconnections. Proceed with caution.

On iOS Spotify starts playing music when attempting connection. This is a default behavior and there is no official way to prevent this with the currently supported authentication flows. You have the option to pass a Spotify URI upon connection or set it to a blank string to play the last played song. There is an undocumented workaround if you don't want music to start playing which is to pass an invalid Spotify URI instead. This is not officially supported by the Spotify SDK or this library and it can fail or stop working at any time!

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
disconnect disconnects the app connection

Player Api

Function Description Android iOS Web
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
setShuffle Set the shuffle mode
toggleRepeat Cycles through the repeat modes
setRepeatMode Set the repeat mode

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

spotify_sdk's People

Contributors

brim-borium avatar itsmatoosh avatar fotidim avatar joran-dob avatar arnav-sh avatar eddwhite avatar mo3rfan avatar ndahlquist avatar nishiths23 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.