I;ve got a program on the PI4 written in python. it uses the os.system command to activate the oxmplayer to play an audio file.
When I run the program in Thonny or from the terminal, it plays just fine.
When I run the program from boot up with rc.local, no audio comes out. It looks like it thinks it’s playing the file, but no noise comes out of the USB speakers or headphone jack or HDMI. What could be causing this / what do I do about it? I need the program to start up when the Pi turns on, as it’s in a sculpture and I won’t be there for every power outage.
please show the line you added to your rc.local. (Issue may be path, permissions, or environment.)
Another thing to try is to change running it via the root cron (sudo crontab -e)
@reboot sleep 60 && /home/pi/play_jingle.sh
# use full path to file so this shell script can be run from anywhere as anyone
Or you can start your program - I start programs with nohup and they continue running:
(sudo crontab -e)
@reboot sleep 60 && /home/pi/Carl/nohup_juicer.sh
runs the script /home/pi/Carl/nohup_juicer.sh 60 seconds after a boot or reboot,
which starts my python program new_juicer.py:
if test -f "$LOGFILE"; then
mv $LOGFILE $LOGFILE".bak"
nohup /home/pi/Carl/Projects/Juicer/new_juicer.py > $LOGFILE &
my code is
python /home/pi/Gulls/Gull1.py &
it does everything in the program except play the media file (which is just a sound effect of “Mine?” from Finding Nemo).
Some things to try:
- Since your program is starting before or at the same time the system services are starting, you might put a time.sleep(5) or such at the start of your program to be sure the sound system is working.
- Add a log output ie.
sudo python /home/pi/sample.py & > /home/pi/Desktop/log.txt 2>&1
- try starting your program with sudo:
sudo python /home/pi/Gulls/Gull1.py &
- Instead of os.system try:
subprocess.check_output(['omxplayer /home/pi/xxx.wav'], stderr=subprocess.STDOUT, shell=True)