I recently acquired a Raspberry Pi (actually…) and started to hack with it. The first thing I wanted to do was a party jukebox.
Music is obviously a critical thing during parties. But everybody wants to play its favorite music from YouTube… And its quickly becoming hard to listen a full track without any interruption…
We could lock the smart-phone/computer which is hosting the music player, but there is another (smarter) solution :)
Mopidy: a music server
Mopidy is an open-source music manager written in Python. It provides dozens of APIs for both music fetching and music management. Even if the project is relatively new, there are several plugins and interfaces to fetch music from YouTube, SoundCloud or Spotify and manage it from HTTP, MPD or even Android.
So, I decided to test it and install it on my freshly installed Raspberry. I connected the jack to a home cinema amplifier, started one track from my laptop and… it works! After some tweaking (pushed Raspberry ALSA mixer volume to 100%), I managed to remove some disturbing “click” and “white” noises.
Time to build a nice interface
However, available interfaces were not designed for parties: there were too many options, and one can quickly remove all tracks from playlist and destroy (almost) everything… That’s why I decided to build another web client for Mopidy, using the Mopidy.js client library.
My aim was to provide a mobile interface for simple actions:
- Get current track name and duration
- Search tracks from the web (YouTube and SoundCloud)
- Add tracks to the current playlist
- Play/Pause music
- Jump to next track ONLY IF current track has played enough (at least 1 minute)
After some nights, I managed to build this basic web extension, thanks to the well documented Mopidy.js API (based on websocket communication):
The source-code is available on GitHub.
Last adjustments before the test-party
Ok, that was cool: the interface works good and the sound was clear. The last thing to do was to provide some network access to the Raspberry interface, which was behind a NAT. I solved that problem by creating a SSH tunnel to my personal server, initiated by the Raspberry with autossh and handled by Nginx on the other side.
http://jukebox.lesterpig.com -> NGINX -> SSH TUNNEL -> Raspberry Pi INTERNET SIDE || LOCAL NETWORK SIDE
I also used a Wi-Fi dongle connected to the Raspberry to create a Wi-Fi access point (using udhcpd and hostapd with this tutorial). It allowed party’s guests to manage tracklist via the provided Wi-Fi connection or their own internet connection.
Mopidy is not designed for security. It’s really easy to use the Mopidy.js API to do almost everything with the player, because it’s handled client-side. But it was not a real problem: with a password in front of Mopidy interface (using Nginx for example), it was easy to limit untrusted access to the Raspberry.
The test-party was a success. No application crash, no music failure, everything worked perfectly. Even with several guests connected to the interface at the same time, Mopidy handled requests correctly.
One missing feature was the volume setup, and automatic playlist management. With no preloaded tracks, Mopidy was unable to play something by its own if the tracklist was empty. It’s something I’ll probably add in a next version of party extension ;)
Wanna try it? Don’t hesitate, you also can install it on a regular laptop; and I’ll be happy to check your feedback. Enjoy!