I'm trying to use a Raspberry Pi create an internet radio player that only needs to play one station, but always plays that station on startup. I know I need mpd and mpc and to enter the URL of the stream, but how do I make that particular stream always play on startup?
you'd want to edit the start up script below
and launch the program.
see this for more details.
You can put your command to run the app in autostart for the lxsession manager. For example, I use the following to setup the autostart script putting with my command :
echo "@lxterminal -e 'audioInjector.RCA.thruTest.sh'" >> ~/.config/lxsession/LXDE-pi/autostart
The "@lxterminal" fires up an lxterminal to execute a bash script once the window manager starts.
You can change that to whatever you want to start by first logging into the Pi or getting up a terminal there and :
echo "yourCommand" >> ~/.config/lxsession/LXDE-pi/autostart
This will add "yourCommand" to the autostart script.
Another option that runs as a regular user and doesn't rely on LXDE is cron. Anything in a
@reboot clause will be run as soon as possible after boot. To edit your cron jobs, enter
An example entry I recently set up for an art exhibition plays an mp3 as a continuous loop:
@reboot sleep 29; nohup mpg321 -l 0 /home/pi/Music/background.mp3 2>&1 > /dev/null
Though it's not a stream player, it should help give you an idea of another way of doing it. The command breaks down as:
sleep 29- a not-very-scientific way of waiting until other jobs have started. This answer might help if you need to understand when various jobs start relative to cron.
nohup … 2>&1 > /dev/null- a wrapper to fully detach and silence any console output from the task I want to run. All output and error messages disappear.
mpg321 -l 0 /home/pi/Music/background.mp3- the player task itself. As with all cron jobs, you need to specify full paths for any data and non-system commands. (As an aside for anyone trying to loop an mp3: you may need to make some special preparations, and iTunes uses its own loop/gapless tags that are generally incompatible with Linux players.)