2

Basically what I am trying to to is create a list of links of which will link to Spotify using a Spotify URI if Spotify is installed and just plain text if it is not installed.

from my knowledge this:

spotify:track:7yOKhepYf8pO8ILT2Z5KN1

If input into the browser and Spotify is installed it will immediately launch the track or what ever you request.

If Spotify is not installed this just runs a normal browser request.

I have looked in documentation for something I can hook into but I just cant find anything that is usable on an external application, Just to reiterate this application is not a native Spotify application.

What I am looking for as an end result is a method to call that checks if Spotify is installed to return true, if it is not installed return false.

The requirement is using HTML CSS and JavaScript Only.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
Daniel Tate
  • 2,075
  • 4
  • 24
  • 50
  • I doubt this is possible. It seems like Spotify links work by the Spotify app registering itself as a URL handler, and you can't detect the available URL handles. (See http://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers). That is, unless Spotify installs a browser plugin. – millimoose Nov 21 '12 at 22:38
  • 2
    It would be a security risk if it was possible, so I doubt it. – Wolph Nov 21 '12 at 22:40

2 Answers2

1

Unless you write a browser plugin with something like firebreath, I do not believe that this is possible for security reasons.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
1

I've not looked too in depth into this yet but you can contact a local Spotify client using the spotilocal.com domain (just a DNS reference to 127.0.0.1) on port 4380.

If it allows CORS then you should be able to call this URL using javascript:

http://1234.spotilocal.com:4380/remote/status.json

And see what the result is.

This is how Facebook does its Spotify integration as can be seen here:

What is the advantage of having a domain name (spotilocal) that resolves to 127.0.0.1?

UPDATE

If you are in Chrome, open your dev tools on this page and paste and run this in the console:

$.get('http://1234.spotilocal.com:4380/remote/status.json', function(data){console.log(data)});

The response header contains Access-Control-Allow-Origin:* so you should be able to call that URL using AJAX from your page

UPDATE 2 (24/07/13)

The newest version of the spotify client (I'm on 0.9.1.57) no longer includes the Access-Control-Allow-Origin header and the method above therefore no longer works.

Community
  • 1
  • 1
Matt Gray
  • 75
  • 9