Software and Other Mysteries

On code and productivity with a dash of unicorn dust.

Spotify Apps 101

This weekend, the Way Out West festival is held in Slottsskogen in Göteborg. I had originally not planned to go, but when I heard that there was a hackathon - which in itself is a tempting prospect - where you got a free pass just for participating, my plans changed.

I teamed up with @rickard_olsson, @jensljungblad and @_sandrahansson with the goal of creating our first Spotify app. In 24 hours we did just that, and the result was a music quiz app called Quizify (the number of apps named -ify was staggering). It was a great hack and we hope to get the chance again next year!

Anyhow! I thought I’d share my experience of doing app development for Spotify.

Resources

The app itself is built purely using Javascript, HTML and CSS which is rendered by Chromium inside Spotify. There are design guidelines that deal with how you should design your app, but the most useful resource is probably the Javascript API.

The Spotify JSDocs are okay. Not more, not less. There is a clear warning on the top of the page that they are preliminary, but more than that, they are very sparse. It’s not a very big API, so it’s easy enough to get around and find what you need, but don’t expect verbose descriptions of methods or events (what’s the practical difference between SEARCHTYPE.NORMAL and SEARCHTYPE.SUGGESTION?). There are code examples for a few common tasks, such as searching and authenticating users using Facebook or other third-party services, but once again they are limited in numbers.

Architecture

To me, Javascript is typically something that is added on top of an application, instead of being the foundation as it is in this case. This probably led to a less-than-perfect architecture. For new projects I would suggest using the index page as a combined layout page and front controller. Layout because it beats copy-pasting all that markup between files, and front controller because any spotify:your_app:param links will be sent to your index.

From there you can load any content you need from other files based on the URL, which consequently means you should use spotify: URIs inside your app as well rather than link to your html-files (which is exactly what we did, unfortunately). This is mentioned fleetingly (sort of) in the integration guidelines, but deserves a lot more attention in my opinion.

Backend

Many apps require a backend, and there is honestly not too much to say here. We used Heroku to host a small RESTful API built in Sinatra and a Postgres database. Just make sure to add the domain of your backend application to the RequiredPermissions in the manifest.json file, because otherwise Spotify will block all your AJAX requests there. The same goes for any outgoing requests, such as third-party authentication. This is covered in the official tutorial, but I wanted to mention it so you don’t forget and spend 20 minutes debugging dropped AJAX requests. Not that it happened to me or anything…

Future

From what I understood, there have been some concerns raised by the record labels regarding the apps. I don’t know exactly why, but I assume this is why there has been relatively little activity since the initial announcement that Spotify was becoming an app platform. It seems however that these issues are soon to be resolved, which hopefully means new momentum for the project in terms of both features and documentation. Perhaps there might even be opportunities to monetize the apps, but I wouldn’t expect that anytime soon.

Comments