Today I spent a little time figuring out solutions for "casting" audio from one device to another. Here are some notes on how to make this happen.
I have an old laptop setup as a media-center PC connected to my TV and receiver. This is pretty much the only set of speakers we have in the apartment so whenever we say "I'd like to listen to some music" we almost always mean "through these speakers". However we don't really have a good source of music these days. Sometimes we listen to youtube, sometimes amazon music, sometimes google music. Sometimes we play audio files from a laptop or desktop.
Ideally, I'd figure out a good media management solution, but until that day a decent stopgap and otherwise generally useful feature would be "play this music here on this device I'm using but make the sound come out of those nice speakers over there".
I'm currently able to listen to Google Play Music or Youtube from Firefox or Chrome on either Ubuntu system in the house (desktop or laptop) or from Google Play music or Amazon Prime Music from my Android phone. Amazon Prime Music is apparently broken (no audio) on Ubuntu period...
In theory this solution should work for any ubuntu application and any app on Android.
I've previously tried or briefly entertained the following solutions:
My current solution is to "enable network access to local sound devices" on the Pulse Audio server running on the media center laptop connected to the receiver. The solution came from askubuntu.com but I'll describe it here as well.
First, install the pulse audio preferences tool on the sound server:
$ sudo apt-get install paprefs
Run paprefs uncheck all of the options on all tabs except for
- "Enable network access to local sound devices"
- "Don't require authentication"
Restart the pulse audio server with:
$ pulseaudio -k
Test the client
Test the client by downloading a sample audio file and playing it through the network to your audio server:
$ wget http://www.signalogic.com/melp/EngSamples/Orig/female.wav $ paplay --server=192.168.x.x:4713 female.wav
Use the ip address of the actual server. If you don't know it, you can right click on the "Network Manager" applet and click "Connection Information" or you can run (in a terminal) ifconfig and read through the output.
Stream browser audio
Run your browser in an environment with PULSE_SERVER=192.168.x.x:4713 and give youtube a try. This worked for me on ubuntu 16.04 (on both client and server) and with chrome and firefox. Amazon prime streaming however doesn't seem to work.
Stream android audio
Solutions came from a couple places:
On the server:
$ sudo apt install pulseaudio-module-bluetooth $ pactl load-module module-bluetooth-discover
Connect the phone and PC using bluetooth. For me, I had to initialize the pairing from the PC, rather than the phone.
In android bluetooth settings for the PC connection, click Use For: "Media Audio" (this was already checked for me).
At this point it should just work. If you go to the unity-control-center "Sound" section (or "Sound" on the dash menu) you should see the phone listed under the "Input" tab.