I too have been intrigued on what it might take to get Chromecast devices to work with something like Volumio.
The main thing to note about the Chromecast is that it has built-in streaming for MP3, WAV and FLAC. To get the chromecast to play your MP3 or FLAC file, you don’t need to actually uncompress a PCM stream and feed it like you would to a sound device but instead only need to host that file on a HTTP server and instruct the device to play the URL. That URL need only be accessible to the chromecast via your own LAN.
Getting Volumio to do all that is a big change from the normal behaviour or streaming to a DSP. So if there is a quick win, it will be with mkchromecast. I will play around with mkchromecast in the coming weeks to see if I can make it work.
But to demo the native chromecast approach I did some tests today using python scripts and pychromecast, I was able to directly stream MP3 and FLAC files to both the normal HDMI-variant and Chromecast Audio devices.
For anyone with a dev background or enough tinkering on a Linux to get by, you may be able to replicate the same simple testing as detailed below:
I installed pychromecast:
sudo pip install pychromecast (or pip3 if you’re using python3). I did this on my Mac. But it will work the exact same way if done on a Pi or any Linux server. You might get some success on Windows if using Cygwin. This library implements the discovery and also media controller interface for Chromecast and makes it quite simple for a python script to control the devices.
Then in my home dir, I put two test flac files…
$ ls *.flac
test.flac test2.flac
One on terminal, I ran the very handy python web server module from my home directory:
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
That runs a simple HTTP server on port 8000 for all IP addresses on that host and serves the current directory as its site root. This will act as a serving node for the FLAC files. If running this on a Mac or PC, you may need to open port 8000 on your firewall to allow other LAN clients talk to port 8000. On a Pi, I don’t think the firewall is usually active and this should just work. To test it, browse to the IP:8000 of the machine and you should see a HTTP directory listing of the current directory contents.
Then this short python script will use the installed pychromecast library to detect chromecasts on the LAN, specifically identify one by name, in my case “Office Chromecast” and instruct the device to stream the desired flac file from the simple python web server. The URL is simply the IP:port/ and I hardcoded that to my machines local LAN IP, port 8000 and the path for the file. The play_media call also specifies the type which in this case was “audio/flac” but could also be “audio/mp3”.
[code]import pychromecast
devices = pychromecast.get_chromecasts()
for cc in devices:
if (cc.device.friendly_name == “Office Chromecast”):
mc = cc.media_controller
mc.play_media(“http://192.168.12.7:8000/test2.flac”, content_type = “audio/flac”)
mc.block_until_active()
mc.play()[/code]
I put this code into a file and ran it with python3. Then the HTTP server terminal showed this output after a few seconds…
192.168.12.107 - - [30/Dec/2018 19:25:09] "GET /test2.flac HTTP/1.1" 200 -
and that is confirming that my targeted chromecast was discovered and directed to play the file. On the video Chromecasts, you get a basic built-in GUI showing the playback progress of the file being streamed.
BTW: I also tried 24/96 5.1 FLAC files. They would not play via the Video Chromecasts but did play via the Audio variant. . I didn’t get a chance to test that via optical SPDIF to my AVR but I suspect that only 2 channels come in as 24/96 in that scenario and that we’re seeing it selecting only the L/R pair or downmixing the 5.1 to 2 on the device itself. It was a pity this doesn’t seem to be supported on the video variant as the HDMI would be perfect for carrying a 5.1 LPCM lossless feed to an AVR.