90% Done!
I still feel a bit uncomfortable about the way everything is "wired" but it works:
- Configured pulseaudio to start up in system mode, removed supend-idle module from .pa file
- Added an mplayer startup script as respawn process to /etc/inittab
- Initialising the FM chip from /etc/rc.local
/etc/inittab
Code: Select all
...
mpl:2345:respawn:/home/pi/mplayer_starter.sh
...
I need to start mplayer as a respawn process, because when I made longer tests, mplayer wiped out from time to time. I want to make sure that it is automatically restarting, when it crashes.
/home/pi/mplayer_starter.sh
Code: Select all
#!/bin/bash -
if pidof -x "pulseaudio" >/dev/null; then
# run as pi user
sleep 1
/bin/su - pi -c "/usr/bin/mplayer -slave -input file=/home/pi/.mplayer_control -playlist /home/pi/audio/playlist.txt -loop 0
fi
sleep 1
I want to make sure that pulseaudio is already running, before starting mplayer. I don't know if it's necessary, but mplayer should run as user pi. This user is member of
pulse and
pulse-access groups. Otherwise I would get an access denied error from mplayer/pulse.
/etc/rc.local
Code: Select all
...
# wait for mplayer
while [ -z $(pidof -x mplayer) ]
do
sleep 1
done
# mplayer is there - initialize radio via I2C
sudo python /home/pi/radio.py
First check if mplayer is already running — this will make sure that there is sound, means: DCLK and FS signals!
The python script needs to be excecuted as superuse, because of GPIO and SMBUS usage. (Strange: I thought rc.local is run by root, but my script failed. I need to put the sudo there...)
Thanks for the pulseaudio hint — It does the job!
Still I'm very open how to make this more elegant. As said — I feel a bit uncomfortable because everything is in a lot of locations, but I could not figure out how to make it better. The main problem is that they are all very dependent from each other:
- radio IC needs PCM signal, before initialising
- mplayer need to have pulse running before starting, etc.
Hans