Prevent song playing on URI link click - spotify

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

Related

Getting a request or notification when changing a track in 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

Is it possible to control the spotify desktop client from a browser with custom controls?

I am a developer for playmoss where users can create playlists with different music services.
We are planning on adding Spotify support to our playlists in a way similar to what bop.fm does.
Context
Taking for example this playlist (in which all songs are available on spotify, at least in Spain)…
https://bop.fm/p/o12l
…if we have the spotify client installed in our computer (tested with a Mac)
As soon as the playlist starts playing we can click the spotify icon on the top right [picture]and we will be playing the songs through spotify.
Using the bop.fm control interface we can pause, play, skip next, even skip to a point in the track with progress bar.
This is similar but even more powerful than the official spotify play button, see an example here:
http://jsfiddle.net/insonorizate/a5jf39yn/
With the play button there is previous, play, pause, next functionality but not seek.
Of course it can not be customized in any way nor called from javascript.
(in bop.fm is possible to open a debuger console and call
Bop.Player.pause()
or
Bop.Player.play()
to pause or play the track beeing played in bop.fm via spotify)
Fiddling a little with the bop.fm page there are some interesting things. Ther is an iframe in the main page poiting to:
https://embed.spotify.com/remote-control-bridge/
Viewing this iframe source we find something like this:
// Expose the OAuth Token to the Javascript
var tokenData = 'NAowChgKB1Nwb3RpZnkSABoGmAEByAEBJReQCFQSFG2Ynvz1oBKgxv2mE1XXz_1Au-cg';
// Pass the remote control to the bridge
var remoteControlBridge = new Spotify.RemoteControlBridge();
remoteControlBridge.init(tokenData);
There's no documentation for Spotify.RemoteControlBridge (0 results for "Spotify.RemoteControlBridge" on google) and there isn't any thing in the documentation of the different apis even close to controling the spotify player in a way similar to this.
Question
How can I control the spotify desktop app from a browser?
Does bop.fm have any special arrangment with spotify and they are using some "secret api"?
Are they exploiting some functionality that I fail to find?
Is it possible to replicate it?
Is it in accordance with the Spotify terms?
Thanks!
You can't control the Spotify Client or Listen to Events the Spotify Web Helper is emitting. Imagine everybody could: every website could potentially play a song without your permission or even know instantly what you are listening to. To prevent this Spotify only allows approved partners to use this feature.
As you figured out the remote-control-bridge provides this functionality. It can communicate with the Spotify Web Helper running on your system, which is secured by an OAuth and a CSRF Token. In the remote-control-bridge you even can see the allowed partners:
Spotify (who knew)
Yahoo
last.fm
coachella.com
bop.fm
sandpit.us
echonest
musixmatch
You can contact them and ask for a partnership. I'm sure they won't bite.
This is actually a little bit documentated on the website of Spotify in the developers section.
I think bop.fm does use their custom Spotify Play Button widget. That makes use of the iframe that you mentioned.
Here you can find the documentation about this functionality of Spotify. You can then modify it to your own needs using Javascript etc.

spotify apps javascript crossfading

How to achieve crossfading on a Spotify javascript based app?
I'm creating a temp playlist and adding songs to it on the fly, the added song plays but doesn't crossfade.
EDIT: I guess the real question is how to cause Spotify to do a refresh of the play queue. the added songs get added to the visible play queue only on the track change, which makes it not crossfade.
There is currently no programmatic access to crossfading in a spotify app (https://developer.spotify.com/technologies/apps/docs/beta/f19ff300f8.html)
However, if the user has crossfading enabled (Settings->Playback->Crossfade tracks) and the model.Player is playing from a context with multiple tracks (like a Playlist or Album) then crossfading should kick in.
The caveat here is that you have to have the next song in the playlist added early-on enough so that the client has time to recognize the change in the playlist. One way to verify if you're adding this in time is to ensure the 'Play Queue' shows that it will play the next song in your playlist.

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.

Spotify Play Button - autoplay?

I am trying to integrate Spotify Play Button into ThingLink Spotify tag so that when the iframe loads, it starts playing automatically. Is there a way to do that with some parameter?
The functionality would be similar to Soundcloud & Vimeo players here:
http://www.thinglink.com/scene/251225958915244034
Without the autoplay, user would have to click on Play twice, which wouldn't be that good of UX.
Thanks!
-Albert
There is no autoplay functionality at present.
Autoplay isn't really what the Play Button is about — it's designed so people can listen to music if they want to. We don't really want to interrupt whatever the user is listening to already (be it something in Spotify, something else, or silence) without express permission to do so first.

Resources