1
votes

I am trying to build an application that plays Spotify songs, among other features. I am well aware that the Spotify API doesn't provide web access to full tracks on desktop. However, I'd still like to explore other workarounds or options. My web app is built on Python and Javascript, so any solution would have to work with those. However if you know of any solutions in other languages, feel free to post those as well. Here are the things I'd like to try before giving up:

  1. Are there any unofficial APIs that provide access to full length tracks? For example, I found this guy https://pyspotify.mopidy.com/en/latest/. Would that one or any other ones be viable to use? I know some of these become quickly deprecated as Spotify updates, but it's best to have something to play for now rather than nothing.

  2. Hidden Spotify play button: Would there be a way for me to embed the play button next to each track's name as a hidden element, and then when I click on my own play button an event is triggered that "clicks" the Spotify play button? I would maybe trigger a click event on the div that the Spotify button is stored in, or have the browser detect its coordinates and click on it. If this seems like a viable option, how would that code even look?

  3. Play track directly to Spotify: I would definitely be ok with clicking on a track and have it play on the user's desktop client or web player. I've been using an app called Unision that does just that. When you try to play a Spotify song, it opens up my desktop Spotify and begins playing the song automatically. If they did it, then there must be a way. How would that solution look like?

Any feedback would be greatly appreciated.

Thank you for reading my post.

2
Please, post your codes you tried.Naman
I'm on the preliminary phase so I don't have much code. I haven't really delved into any of these options because I don't know if they're even possible.user2030942
I don't know about the first two, but the third one is handled via a Spotify URI. Eg: spotify:artist:0Ya43ZKWHTKkAbkoJJkwIBMorgan Thrapp
That works! I figured out a solution to the 3rd option. If you call the track URI with the autoplay option set to true, then it starts playing automatically. Here's an example: spotify:track:3rTIcUMMP2Ez33DfjJlb9e:autoplay:true Still, I'm leaving the question open so if anyone has an answer to either the first or second options those can be explored as well.user2030942

2 Answers

3
votes

Arielle from Spotify here. At the time of this question, there was no way to play full tracks in the web. For those of you looking at this in the future, you can now use the Web Playback SDK!

https://beta.developer.spotify.com/documentation/web-playback-sdk/

The Web Playback SDK is client-side JavaScript library which allows you to create a new player in Spotify Connect and play any audio track from Spotify in the browser via Encrypted Media Extensions. It’s the same technology we use to power our Web Player experience.

Some things you can do with the Web Playback SDK:

  • Create a new player in Spotify Connect
  • Stream an audio track in supported browsers
  • Get metadata for the current track
  • Get metadata about the user’s listening session
  • Control local playback (pause, resume, volume, etc)

Happy hacking!

0
votes

I solved this by using the third option and calling the track URI with the parameter autoplay:true. So to call a particular song from my code, I would just refer to the following URL:

spotify:track:3rTIcUMMP2Ez33DfjJlb9e:autoplay:true

which makes the song start playing automatically on the Spotify Client.

If anyone has any suggestions as to how to approach ideas 1 and 2, those are still options worth looking into.