I had to struggle a bit over silly issues to get this working, so documenting it for others. Tried on Linux raspberrypi 4.14.90-v7+ #1183 SMP Fri Dec 21 14:03:50 GMT 2018 armv7l GNU/Linux. Even minor version changes can make this guide irrelevant, so use at your own risk.
# apt-get install alsa-base alsa-oss alsa-utils alsa-tools mpg123 # apt-get install libasound2 libasound2-plugins alsa-oss # aplay sample.wav # apt-get install pulseaudio pulseaudio-utils
As of 2018/12/31, pulseaudio on Debian is expected to run as ordinary users and does not have a start script to run at boot time. It is important that pulseaudio and gmediarender run as daemons as the same or compatible users. Here is a systemd script I used.
[Unit] Description=Pulseaudio sound server After=avahi-daemon.service network.target [Service] ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
Write the above into /etc/systemd/system/pulseaudio.service and issue these commands to enable start at boot.
# systemctl enable pulseaudio.service # systemctl start pulseaudio.service
$ paplay sample.wav $ paplay sample.mp3
First install gstreamer and gmediarender.
# apt-get install gstreamer1.0-alsa gstreamer1.0-plugins-base gstreamer1.0-plugins-good gmediarender
In /etc/default/gmediarender, set ENABLED=1. Configure gmediarender to use pulseaudio using gconf. Enable the service and test it.
# systemctl enable gmediarender.service # systemctl start gmediarender.service # /usr/bin/gmediarender -f Test --logfile /dev/stdout
See instructions here or here on how to switch between HDMI and analog outputs without depending on autodetect.