Spotify Next Track Button

Wouldn't it be handy to have a big button you could hit that would activate the Spotify Next Track button? It wasn't that hard to do! I had the prototype working in couple hours.

The reason for this is that I often listen to other people's public Spotify playlists, and there are always a few songs I don't really like and would rather skip over. Hitting the next track button when I'm sitting at my Mac is no problem, but I use Airfoil and Apple Airport Expresses to pipe music all over my house. It's less convenient from my kitchen.

I could open up my iPhone and use the next track button in Remoteless, but that takes several seconds. A big button would be more fun.

Before you get too excited about this project, I should warn you that not all of the code is included. There is a piece that's not published. I'll tell you how it works, but you'll need to implement that yourself. Sorry about that.

The hardware couldn't be simpler. This is my prototype, which has a little button, but it works the same as the big button. It uses a SparkCore from It's a tiny computer designed to work with the cloud. It's mostly software compatible with the Arduino but with built-in Wi-Fi and cloud computing support. It's powered by Micro USB and can be battery powered. And it's only $ 39!

The button is connected to the D0 input, and the inputs can be configured with internal pull-ups, so the switch only needs to be connected to ground. Easy!

I got the button from SparkFun for $ 9.95. It comes in several colors, and there's a less expensive version for about half the price. It's big - almost 4" (100 mm). The button has an light in it, but I did not use the light in this project - I only used the switch.

I also got the mini-modular protoboard from SparkFun for $ 3.95. It's not strictly necessary, but it's a convenient size to fit inside the project box. That's not the one above, that one came with the SparkCore, but I wanted a smaller one inside the box. A soldered protoboard would also be a reasonable choice.

Finally, I got the 2A (5V) micro-usb power supply from SparkFun for $ 5.95. Any micro-USB power supply will work. And the SparkCore uses a miniscule amount of energy - less than 1W at 120V at the wall plug with this power supply.

The only other thing I purchased was a box from Digi-Key, $ 8.40. It's a 4.6" x 4.6" x 2.4" Black ABS plastic utility box. It was just the right size for the button.

You set up the SparkCore first using the smartphone app, associating it with your account and telling it your Wi-Fi password.

Programming it is done using Wiring, the same C-like language as the Arduino, but you can program it right from your web browser and flash the Spark over Wi-Fi. It's pretty cool. Here's my code:

Not much to it! The main thing is that when you press the button an event is sent into the cloud.

One of the nice things about the Spark system is that even though my code is essentially listening for events, my code makes requests outbound using HTTP Server Side Events (SSE). This eliminates having to open ports in the firewall, deal with dynamic IP addresses, etc.. Easy and pretty efficient.

My code is written in Java and runs in Apache Tomcat. I'm not releasing the source because it contains a bunch of proprietary code that I don't want to release. That infrastructure is why I was able to write it so quickly, however. But I will explain how it works, and you could easily do something similar in your favored language.

The Java code basically runs a SSE client that makes a connection to the Spark API server and waits for messages. If the connection is lost, it just makes a new connection. One of the messages is an event message, which signals that the button was pressed. I then call an AppleScript to trigger Spotify to advance to the next track.

And finally, the AppleScript. This tells Spotify to advance to the next track. I'm not sure if Spotify for Windows has similar capabilities, but this is super quick and easy on the Mac. Well, if you have Java code that can use osascript on the Mac to interface with AppleScript. That's left as an exercise for the reader.

As for the box, mark the location of the holes:

I started with smaller drills are worked up to larger sizes to reduce the risk of shattering the box, though ABS is pretty forgiving. The side hole is for the power supply and is 1/2" (the USB connector end needs to fit through it). The top hole is 1" to hold the switch, though I only had a 7/8" twist drill so I used that and just widened it a bit with rocking the drill bit and a utility knife.

drilled.jpgThis is what the button looks like:

button.jpg button_bottom.jpg
On the bottom is the microswitch and lamp (not used). A little twist allows that to be removed, at which point you can unscrew the white nut.

Here are the leads soldered to the switch after I mounted the switch the top of the box.

And here's the insides:

And that's it. The final product is show at the top of the page.

About this Entry

This page contains a single entry by Rick Kasguma published on October 21, 2014 5:24 PM.

iOS WebView error and debug logging was the previous entry in this blog.

Oil fill sensor is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.