Sound file playback on boot

Hi all,

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.

thanks!

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

play_jingle.sh:

#!/bin/bash

# use full path to file so this shell script can be run from anywhere as anyone
omxplayer /home/pi/jingle.wav

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:

/home/pi/Carl/nohup_juicer.sh:

#!/bin/bash
LOGFILE=/home/pi/Carl/juicer.out

if test -f "$LOGFILE"; then
    mv $LOGFILE $LOGFILE".bak"
fi

nohup /home/pi/Carl/Projects/Juicer/new_juicer.py > $LOGFILE &

Hi!

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:

  1. 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.
  2. Add a log output ie.
sudo python /home/pi/sample.py & > /home/pi/Desktop/log.txt 2>&1
  1. try starting your program with sudo:
sudo python /home/pi/Gulls/Gull1.py &
  1. Instead of os.system try:
import subprocess
.
.
.
subprocess.check_output(['omxplayer  /home/pi/xxx.wav'], stderr=subprocess.STDOUT, shell=True)