Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gpenverne/chromecast-audio-cd-caster

Stream an audio cd to a chromecast
https://github.com/gpenverne/chromecast-audio-cd-caster

audio-cd chromecast chromecast-audio icecast-server raspberry-pi

Last synced: 12 days ago
JSON representation

Stream an audio cd to a chromecast

Awesome Lists containing this project

README

        

# Stream an audio cd to a chromecast

We will use an icecast server, to install it:
```bash
$ sudo apt-get install icecast2
```
Icecast2 server will broadcast the audio feed

And we need ffmpeg, which will stream audio cd to icecast2 feed:
```bash
$ sudo apt-get install ffmpeg
```

Some configuration, for icecast2: edit the ``/etc/icecast2/icecast.xml`` file, and check the authentication part:
```xml


YOUR_PASSWORD

YOUR_PASSWORD


admin
YOUR_PASSWORD

```
And the hostname and socket part:
```xml
localhost

8000

```
You can see the full config file in the [Chromecast-audio-cd-caster repo](https://github.com/gpenverne/chromecast-audio-cd-caster)

To stream using ffmpeg, simply use:
```bash
/usr/bin/ffmpeg -f libcdio -ss 0 -i /dev/cdrom -acodec libmp3lame -ab 48k -bufsize 15 -ac 1 -content_type audio/mpeg -f mp3 icecast://source:[email protected]:8000/raspi
```
(Don't forget to replace 192.168.0.31 by your raspberry pi local ip)

You have now a feed readable from http://192.168.0.31:8000/raspi

### How to cast?
To cast what you want to a chromecast, have a look on [Pychromecast](https://github.com/balloob/pychromecast)
Of course, you need python3:
```bash
$ sudo apt-get install python3
```

And a tiny python script:
```python
import time
import pychromecast
import urllib.request

stream_url = 'http://192.168.0.31:8000/raspi'
chromecasts = pychromecast.get_chromecasts()
cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Salon")
cast.wait()
print(cast.device)
print(cast.status)
mc = cast.media_controller
while urllib.request.urlopen(stream_url).getcode() != 200:
print('Waiting for stream up')
time.sleep(1)

mc.play_media(stream_url, 'audio/mp3')
mc.block_until_active()
print(mc.status)
mc.play()
```

And ... it's a kind of magic:
```bash
$ /usr/bin/ffmpeg -f libcdio -ss 0 -i /dev/cdrom -acodec libmp3lame -ab 48k -bufsize 15 -ac 1 -content_type audio/mpeg -f mp3 icecast://source:[email protected]:8000/raspi & /usr/bin/python3 /home/pi/audio/cast.py
```

### Bonus: autostart on cd insertion
We will use an udev rule, for example in a ``/etc/udev/rules.d/99-cd-audio-processing.rules`` rule:
```
SUBSYSTEM=="block", KERNEL=="sr0", ACTION=="change", RUN+="/home/pi/audio/start-cd.sh &"
```

Reboot, and you're ready :)