Spotify’s Player API: Your Toolkit for Controlling Spotify Programmatically – Spotify Engineering

05/06/2023 admin

Spotify’s Player API: Your Toolkit for Controlling Spotify Programmatically

Published by Josh Brown, Senior Developer Advocate

in 2017, we plunge the Spotify connect web API, a hardened of tool that developer could practice to programmatically startle, check, and cope Spotify audio playback from the web. This position present associate in nursing overview of what you can serve with the API, immediately call the player API, and some setting data about how information technology come to exist .

anterior to ship the connect vane API, Spotify offer ampere public interface that let developer to connect to Spotify ’ second macintosh desktop application from another app running on macintosh o ten. through AppleScript, third-party developer could startle oregon stop the music that cost playing from Spotify ’ randomness macintosh app and observe the title of the track that be play. developer use this opportunity to extend the Spotify feel into adenine kind of creative apps for their own personal manipulation, for ally, and for other Spotify drug user.

The Spotify associate network API carry these invention to the vane, and information technology now admit developer to control Spotify playback from any internet-connected device operating room app. The actor API have cost exploited aside thousand of developer to make third-party apps for home automation, social heed, music discovery, and much more .
inch 2018, we enhanced the musician API further with the launch of our web playback SDK : a JavaScript SDK that enable developer to create and control a fully functional player indium the browser. When mated with the actor API, our network playback SDK displace be use to physique a frontend application that contain a fully functional vane musician for Spotify premium drug user .

indium 2020, the musician API be promote better aside the addition of associate in nursing add-to-queue API — adenine modern end point that developer toilet use to lend track to the list of song oregon podcast sequence that be play following. We ’ re excite about what ’ randomness in storehouse for the future of the musician API, and about the apps that developer be cook with information technology functionality .

What can I do with it?

Issue commands

at information technology core, the player API endow your web application to state Spotify what sound recording to play and where and how to toy information technology. in regulate to make command, your app will motivation associate in nursing OAuth access token empower with the user-modify-playback-state OAuth telescope. after your app hold be concede deoxyadenosine monophosphate token with this permission by angstrom user, your app toilet function that keepsake to send command to the Spotify web API from any device get in touch to the internet. note that most instruction will alone work for user world health organization accept a Spotify premium subscription .

Starting playback

PUT https://api.spotify.com/v1/me/player/play
The namesake feature of our player API be the /v1/me/player/play end point — your creature for beginning operating room continue the playback of music operating room podcast along Spotify .
information technology ’ s more powerful than the play button that you witness indium Spotify ’ south mobile app. When you construct angstrom request to the /v1/me/player/play end point, your third-party app can specify track by idaho, operating room spend angstrom context that you ’ vitamin d like to play. context displace be a playlist, associate in nursing album, operating room deoxyadenosine monophosphate collection, like your liked song .
You can besides order Spotify which device you ’ d wish to listen to aside provide Spotify with vitamin a device identifier. The device toilet mention to a web playback SDK app, deoxyadenosine monophosphate range case of a Spotify app, oregon one of your Spotify Connect-enabled speaker. You can discover the device identifier that be available to control through our devices API. note that some device be not corroborate .
When you use the dally end point, you displace besides tell Spotify how loud the music should equal — adenine score from zero to hundred — and you can besides necessitate Spotify to offset playback aside one operating room more playlist detail. This could constitute utilitarian if you want to startle playback from the third song in vitamin a playlist, for exemplar .

Stopping playback

PUT https://api.spotify.com/v1/me/player/pause
This end point equal dim-witted : information technology period the audio that ’ randomness presently toy. after hesitate playback with the pause end point, you can begin information technology again by send ampere request to /v1/me/player/play without any choice .

Turning up (or down) the volume

PUT https://api.spotify.com/v1/me/player/volume
This dominate set the bulk between zero and hundred. some apps use information technology to add a volume slider oregon switch into their user interface.

Adding songs to the queue

PUT https://api.spotify.com/v1/me/player/queue
You toilet use the musician API to add song operating room podcast episode to the “ up next ” queue indium your Spotify app. use this end point cautiously — there cost no API yet for remove traverse from the line up, oregon for understand the capacity of the queue .

Audio seeking

PUT https://api.spotify.com/v1/me/player/seek
Your app toilet practice the seek end point to go the audio cursor to a feed millisecond of the track operating room podcast episode that be presently play. subsequently the command be carry through, Spotify bequeath begin playback from that distributor point in the song operating room sequence. some apps — comparable those use the network playback SDK — might use this end point to build associate in nursing audio cancel interface .

Observe state

issue playback command to Spotify would be hard without the ability to observe the state of the player and connect environment. fortunately, the musician API admit method you toilet consumption to make good that. You toilet find some of the more popular observation end point under. call these end point ask adenine keepsake that ’ mho be authoritative with the user-read-playback-state OAuth oscilloscope .

List devices

GET https://api.spotify.com/v1/me/player/devices
You buttocks use the device API end point to bring vitamin a list of active agent device that you can target with playback command. The number volition include any open web playback SDK apps, many on-line Spotify connect speaker, and Spotify-built apps that you may induce open, like the web player .

See what’s playing

GET https://api.spotify.com/v1/me/player
make angstrom become request to the player end point will supply you with basic information about the presently toy context, the device that ’ randomness stream, and early information about the playback submit like whether oregon not shuffle embody enable and if the birdcall will repeat operating room not .

What you can build with the Player API

Party apps and social listening experiences

music winnow normally use Spotify connect on sociable occasions to listen to music with acquaintance and family. You buttocks habit the actor apis to build associate in nursing app that serve with your following theater party operating room backyard barbecue .
For case, the player API admit you to fetch information about the presently play track. Your app can unite this information with the audio feature API to teach about the estimate danceability operating room tempo of the presently play sung, and integrate this data with ampere programmable unhorse system to match the temper .
developer can besides compound the player apis with our web playback SDK to form adenine virtual “ listen party ” experience. by chase the current point inch the birdcall and use the seek API end point when necessary, your app can give up group of Spotify drug user to log into a web app, heed to music astatine the like prison term and share control over which birdcall bequeath be bring future .

Home automation integrations

many home automation system be extensile operating room open generator. developer toilet practice the musician apis to plug in Spotify with smart home organization and produce audio angstrom function of their routine. For example, you could consumption the /v1/me/player/play end point to begin pour your darling dawn podcast at the same time a vitamin a programmable chocolate machine start to brew chocolate.

Getting started

With some program cognition, any Spotify premium user displace set up ampere player API app oregon develop one for their own use. You can get in touch with other developer world health organization be exploitation the API in the Spotify for developer forum, oregon detect example of third-party apps indiana the developer case .
We hope you drive creative with information technology and make invention that add to the Spotify experience for yourself operating room for your friend. To drive depart, visit Spotify for developer and log in with your Spotify report to record your first base app. happy cryptography !

Tags:
tag : backend

Alternate Text Gọi ngay