Inspiration

Spotify recently added Connect endpoints to their web API. Included in this is the ability to control playback of music and change which device is playing! Wouldn't it be cool if you could have your music playback follow you around the house?

What it does

As you walk into different rooms, Spotifly will automatically change which device is being used for playback.

How I built it

It uses beacons to represent where the nearest speaker is. Based on the strength of the signal received from the beacons, it works out how far you are from them and hence which one you're closest to. It then looks up the Spotify device ID linked to that beacon and makes an API call to switch to that device if it isn't already!

To prevent it from flicking endlessly between devices, there's a bit of averaging in there, as well as a bit of decay on the calculated distance to each beacon (so that if no signal is received for a while, the calculated distance increases).

Challenges I ran into

I initially wanted to use WebBluetooth to scan for the beacons. This way, we could use a mobile browser as the scanning device - a phone is easier to carry around that the laptop which we ended up having to use! Turns out WebBluetooth is still a bit young, and doesn't (as far as I could tell) have support for BLE scanning.

Accomplishments that I'm proud of

It works. And it works pretty well - you can walk around and the music changes!

What I learned

A whole load about Bluetooth LE and how advertising packets work. I knew a bit from past projects, but now I know even more!

What's next for Spotifly

Maybe include other ways of measuring distance. Beacons are great and all, but they're not very accurate when it comes to distance. It might be worth using motion sensors or something.

Also it makes more sense to be carrying a beacon itself around, rather than a device which is scanning for them. This method requires more actively scanning devices though, and they all need to talk to each other to work out which is closest to the beacon.

Share this project:

Updates