Getting a request or notification when changing a track in Spotify - spotify

I want to write a program that writes the music name to a social network status. When changing a track in Spotify, I can get the name of the music, but I don't know how to get a notification when changing music.
How do I get a callback when changing a track in Spotify's API?

You might be able to use the Web Playback SDK with player-state-changed to get these events, but this will depend on what you are going to write your programme in but it might help to look at this and see if it does what you need

Related

Add music to dialogflow

I am trying to add music into my dialogflow agent. I don't want to add it from the dialogflow console and I wish to add it from the webhook. Can you please tell me how to add the music from the webhook. I am trying this code but it's not working:
app.intent('Music', (conv) => {
var speech = '<speak><audio src="soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_countdown_loop_32s_full_01"/>Did not get the audio file<speak>';
});
Also I want to use one interrupt keyword which will stop this music, is there any predefined way or if user defined, how to interrupt the music and proceed with my other code?
Firstly, to be able to add music, it needs to be hosted on a publicly accesible https endpoint, see the docs. So make sure you can access your file even when using a private browsing mode such as incognito on chrome.
Secondly, If you choose to use SSML to play your audio, the audio will become part of the speech response. By doing this, you won't be able to create any custom interruptions or control over the music. The user can only stop the music by stopping your action or saying "Okay Google" again to interrupt your response.
If you would want to allow your users to control the music you send to them, try having a look at the media responses within the actions on google library.

Spotify API player update event

Basically I want to display the current track on a website.
I already searched quite a bit for a possibility to get notified when player state (play/pause, track, current position) changes.
My question:
Is it possible to get notified (socket, hook call) or is the only possibility I have to call the Web API like every second and fetch the state?
I fear that I'm running into rate limits when multiple users connect their accounts and display the current track.
Nope, there's still no way to do that. To achieve what you'd like, you need to pool the Spotify API continuously.
You can however use the Spotify SDK that you can pass a function to be executed on playback state change. The SDK is incompatible with a few platforms (see supported browsers), but for those you could catch the SDK initialization error and then switch to continuous polling via the API. You will have a lot fewer requests then.
A second option would be to only update the currently playing song after the last song should have ended. When getting the playback state for the currently playing song, you could use the field duration_ms and progress_ms to calculate the remaining time of the song. Then schedule another API requests for when the song should have ended and you're good. Whether that's a good strategy for your use case or not depends on the type of playback and how often the playback changes in your app.
I hope I could help!
As of now, it seems to be possible to receive player state events with a listener:
https://developer.spotify.com/documentation/web-playback-sdk/guide/#playback-information-display
I haven't tested the Web version, I'm currently using the analogous Android APIs, and Android's seems to work for play/pause change and track change (but not for position change)

How to lookup Spotify User metadata (playlists, currently playing, etc)

I only see Artist, Album, and Tracks lookups in the docs. I want to display what I'm currently listening to. Is there a way to do this using the API?
https://developer.spotify.com/technologies/web-api/lookup/
Spotify does not provide this at this time. You can either get it by turning on last.fm scrobbling or accessing facebook music data.
As Thomas said Spotify does not provide such a feature 'directly'.
But there are some ways to get it work.
You have to me some more sprcific what you want to do. Web/Desktop/App
I wrote a tiny console app using an external dll
"File/Link removed" - send pm for further information!
If this is what you need just message me. It's a rly tiny application just for test purposes! Because I currently develop a overlay.

Prevent song playing on URI link click

I'm working on a Spotify app where I'd like for users to be able to click on track names and be linked to the track page, just like in other Spotify apps. I'd like to prevent the song from beginning playback, though.
SoundDrop seems to do this. You can click on a track name and the song doesn't interrupt playback by SoundDrop.
I'm not sure how to implement this alternative behavior. Any ideas?
The Apps API uses standard JavaScript stuff, so if you attach a handler to the track link and use e.preventDefault(), that should prevent Spotify playing the track and you can then do your own custom handling.
More discussion on e.preventDefault() is here: event.preventDefault() vs. return false

Territory restrictions and linked tracks in Spotify

I am building an app that needs to know if a track is playable in the user's region.
It's easy to check the basic territorial restrictions of a track using the Metadata API. However, I am encountering tracks that the Metadata API says are out of my region, but are auto-linked to versions of the same track that aren't region locked. ie. Metadata says I can't play a track, but as far as the user is concerned, Spotify can play that track.
Here's an example:
'Sweet Unrest' by Apparat # spotify:track:4H4h3ulzjGVox14GHiCEoo
I am in the UK (territory code GB)
The lookup link is http://ws.spotify.com/lookup/1/.json?uri=spotify:track:4H4h3ulzjGVox14GHiCEoo
There is no GB code in the resulting territories string, so in theory, I should not be able to play the track. However, in the main Spotify player, I can see that it is auto linked to spotify:track:11S6TQybYumAnNApugZWSJ which is playable in my region. If I paste the supposedly unplayable track's URI into the top left Spotify search box, it plays.
Is there an API based way to check for tracks like this?
You can detect whether a track is playable or not using an undocumented property of each track: data.availableForPlayback
Track.fromURI("spotify:track:XXX", function(track) {
alert(track.data.availableForPlayback);
});
If you run the code above, you should get a True/False that does what you're after.
Unfortunately not, not at this time. The linking is actually done by the client itself rather than any of our backend services, so none of our APIs have this information.

Resources