Streaming any audio source from Ubuntu to Android

Wednesday, Jul 8, 2015

One of the advantages of treating my home PC as an always-on server, with its own semi-static IP address, is that I can have access to my music from my phone.

Having achieved this, with the help of Subsonic, the next step was playing music through the speakers wired to a Lepai amp. The simplest way was to get a bluetooth receiver and pair it to the old Nexus One phone that I still have with its original cradle. (I couldn’t connect the phone directly to the amp, since the outlet is powered off from a wall switch, and the phone would take too long to boot.)

The music that I could play was basically the library available via UPNP/DLNA (using BubbleUPnP), and radio stations from the phone’s TuneIn Radio app.

However, I’ve been listening to Spotify lately, and it runs extremely poorly on the Nexus One. Enter today’s solution.

First step is to install the app that Spotify recently made available for Ubuntu, and get it running properly. Next, install PulseDroid on the NexusOne, downloading the apk file directly. (There’s also Simple Protocol Player available on Google Play, but I had good results with PulseDroid.)

Following the instructions on the Github repo, I had to find out the exact name of the output card, with the intention of creating a PulseAudio monitor that replicates the sound played through that card:

$ pactl list | grep Name.*monitor
	Name: alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
	Name: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor

And then creating the recording device, setting it to monitor the sound card output:

$ pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor record=true port=8001 listen=<LOCAL_SERVER_IP>

When Spotify plays music through that sound card, the audio goes to the headphones and at the same time, to the recording device just created. Then it’s just a matter of running PulseDroid on the phone, and pointing it to the server’s IP and port.

Installing and running pavucontrol can help with seeing the devices and the current sound level of audio being played through each one.


I found another, more stable alternative:

Run BubbleUPNP on the Nexus One, which (when licensed) can be set to run on boot and stay on while the phone is powered.

Install pulseaudio-dlna and run this command on login:

pulseaudio-dlna --filter-device='Nexus One KitKat'  &

This creates a Pulseaudio output device; pavucontrol can then be used to direct the audio from any running application through this device.