Is it possible to play an entire song using the Spotify API? - spotify

I know that it's possible to access a user's songs using the Spotify API, but is it possible to automatically play a given one also using the API (i.e. is there some method (like 'play') that automatically plays the song on the user's device given the song name that you already retrieved?). Thanks!

No, libspotify is only an API to fetch data so to speak.
What you do get from it is the callback music_delivery(sp_session *session, const sp_audioformat *format, const void *frames, int num_frames), which as you can see contains frames, which is raw audio that needs to be played by another framework for example.
I'd suggest reading Spotify's examples in order to learn how to use this.

Related

Accesing my account on spotify and playing liked songs python

I want to create a program that, if called, will access my liked songs playlist on Spotify and play either a random song or a song that has been called. I know that I should use the Spotify library, however, I don't really know how to achieve my goal, as most tutorials are about creating a new playlist or something of that nature, not accessing an already present playlist like liked songs.
Any advice will be appreciated:)
You could use the pyspotify library. This part of the documentation goes in detail on how to play music and mess with playlists.

Getting spotify desktop player status

I come from an electronics background, with a project whereby I'd like to be able to obtain various information about the state of the desktop player, eg
Current track name
Current track artist
Position in song
Play/pause status
Is there an active API or other method which will allow me to obtain this information and get it out of the desktop app itself, such that I might be able to send that information out via a COM port?
Thanks in advance.
You could use my .NET Library SpotifyAPI .NET
It combines the spotify-local and spotify-web API.
Also, it provides all your required information and is simple to use.
Small example:
SpotifyLocalAPIClass spotify = new SpotifyLocalAPIClass();
if(!spotify.Connect())
return;
SpotifyMusicHandler mh = spotify.GetMusicHandler();
SpotifyEventHandler eh = spotify.GetEventHandler();
Console.WriteLine(mh.GetCurrentTrack().GetTrackName());

Create app-bound playlist on Spotify

Is it possible to create an app-bound playlist?
It's possible to create a playlist for a user, but how will I know which one that is when they move away from my app?
Ideally, I would only need to be able to create/edit 1 playlist.
Edit: Have found this http://developer.spotify.com/technologies/apps/guidelines/integration/#appsthatcreateplaylisturi:s
But if anyone has great ideas, I'm still open!
As you've found out yourself, you can't create a playlist in a user's library that's somehow linked to your application using the Spotify Apps API.
I thought it'd be a good idea to also quote the relevant part of the Integration Guidelines that you've linked to:
If you want to generate and save the user’s personal playlists in the
app, you should not keep playlist information only saved within the
app. Playlist information should instead be handled by utilizing user
playlists, so that the user can access playlists as usual. They
shouldn’t have to go to the app to access a certain playlist that they
have created.
Suggestion:
I think there's several ways to do what you want to do though.
One way could be to let a user create a new playlist using your application and save it to the user's library, and at the same time save the playlist URI to your own back end. As you've noted, playlist URIs are obfuscated (e.g. they look like spotify:user:#:playlist:783BHaT7Xb8K5VyYstxsj3 instead of spotify:user:thelinmichael:playlist:783BHaT7Xb8K5VyYstxsj3, the username is replaced by # for the currently logged in user, and #xxx.. for other users). You could still save the last part of the URI, which I believe is unique for every playlist. Using a hashmap to map that part of the playlist URI to properties you want to keep track of would let you do quick lookups of a user's playlists to see if they are associated to your app. You could iterate though the user's library to gather all obfuscated URIs, and send them to your backend in a single HTTP request. The response from your server could be the index of the library playlists that matched the playlist on your backend, along with the properties you've mapped to it. Again, this was just a suggestion and possibly not the best way forward but I hope it gave you some ideas. :-)

Spotify vs Last FM, display last played track

I was looking for a way to display my last played Spotify track on my website. I succeeded using the Last.FM API. Spotify doesn't have an open API and the music part of Facebook seems to be locked down too. So I now scrobble everything to last.fm and use their API to get the last played song. This works fine, but I thought it would be fun to display a "play now" button to play the track on spotify.
To do that, I need the Spotify ID for the particular song, which the last.fm api doesn't seem to return.
So... two questions:
1) is there a way to get the same info from Spotify itself?
2) if not, is there a good way to get the matching spotify song using the Last.FM details?
1) No. Spotify doesn't have a play history API. However, you can use Facebook's listens endpoint if the user is publishing listens to Facebook.
2) Not directly, as far as I'm aware. However, a quick Google turns up this project. Failing that, you can use the Spotify Web Search API to search for a track matching the metadata. The Advanced Search Syntax may come in handy here.

Is there a way to search currently playing songs for every user using the Spotify API?

I just want to experiment writing a little app that will let you know how many people on spotify are listening to the same song you are. Not just your friends but everyone!
given the responses to similar questions that can be found here, here, here and here I would say that it is probably not possible for privacy reasons, as the spotify API does not intend to let you access the users spotify id which would be required to get the tracks you where listening to.

Resources