0

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?

1

you'd want to edit the start up script below

/etc/rc.local

and launch the program.

see this for more details.

1
  • that's really only a link-only answer. You do have to be a bit careful with rc.local, as it's running with elevated privileges and you have to ensure that your task forks to allow other startup items to run – scruss Jan 15 '17 at 15:09
0

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.

1
  • This will work as long as the user Pi has autologin enabled. Otherwise this won't work at boot until Pi logs in. – Andy Anderson May 11 '18 at 17:00
0

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 crontab -e.

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.)

0

You could create a watchdog script that runs in crontab every minute. This will also restart the stream if for some reason it crashed.

#!/bin/bash

if [ -z $(ps aux | grep "[the command that runs your stream]" | grep -v grep) ]; then    
 [the command that runs your stream] & 
 else exit
fi

exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.