After updating a Raspberry Pi to Debian Stretch, I noticed that the older article with Jessie does not work anymore. It will be described how to listen to a webradio with Raspbian Stretch.
Getting Raspbian
Download Raspian Lite, extract the zip file and copy the image onto your microSD card using the linux command line:
unzip 2017-08-16-raspbian-stretch-lite.zip
sudo dd bs=4M if=2017-08-16-raspbian-stretch-lite.img of=/dev/mmcblk0 status=progress
sudo sync
The Raspbian Lite version is very slim, compared to the full Desktop version, but the latter is not necessary for headless running. Instructions for other operating systems are described at: Writing an image to the SD card.
Initial Setup
Insert the SD card into your Raspberry Pi, connect the Power and Ethernet cable. You could either configure Rasbian remote by enabling ssh or local with a keyboard. In any case using default user pi and password raspberry to make the base configuration:
sudo raspi-config
Now expand the filesystem, set a new password, run internationalization options, change the hostname in the advanced settings and enable ssh if not already done. Then finally do a reboot.
After that install the latest updates:
sudo apt update
sudo apt upgrade
Webradio Setup
With Debian Stretch mplayer2 is replaced by mpv, which is a modern fork and rewrite:
sudo apt install mpv
Connect the Raspberry Pi using a 3.5 mm cable to your radio through the AUX input. Test your setup with you favorite webradio stream url, in my case sunshine live:
mpv http://stream.sunshine-live.de/hq/mp3-128/Facebook-og-audio-tag/
Useful mpv commands:
9/0 -> lower/higher volume
q -> quit
Maximize alsa sound output permanently:
amixer cset numid=1 -- 400
Run mpv at startup with Debian Stretch
To configure a automatically restart of mpv, create a new file i.e.
/etc/systemd/system/mpv.service
[Service]
Environment=TERM=linux
ExecStart=/usr/bin/mpv --ao=alsa --volume=130 --no-video --no-ytdl --really-quiet --network-timeout=5 http://stream.sunshine-live.de/hq/mp3-128/Facebook-og-audio-tag/
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
In case the webradio stream disconnects or you got a forced disconnect by your ISP, the network timeout is set to 5 seconds. If the program crashes or exits by a network timeout, it will always restart after a 10 second wait. So in a worst case scenario, you have 15 seconds where the audio output stops.
Now activate the new mpv service
sudo systemctl enable mpv.service
Just reboot or start the service manually
sudo systemctl daemon-reload
sudo systemctl start mpv.service
Later you could inspect that everything works fine
systemctl status mpv
journalctl -u mpv.service