Giovanni Bauermeister Giovanni Bauermeister - 2 months ago 19
Bash Question

aplay does not play audio when run by systemd

I'm developing a Qt application which includes the following block of code to play sound

QString soundApp = "/usr/bin/aplay";
QStringList soundFile;
soundFile << "/home/pi/urna-files/sources/som-longo.wav";

QProcess *playSound = new QProcess;
playSound->start(soundApp, soundFile);


The sound plays fine when the app is run from command line.

When I use systemd and unit file to start the application after boot, QProcess does not play the audio.

[Unit]
Description=Voting Machine Launch Service

[Service]
ExecStart=/home/pi/urna
Restart=always

[Install]
WantedBy=multi-user.target


What should I do to have it working? Is there something more to add in the unit file? or any other argument for QProcess?

Answer

The process probably needs to be run as the user "pi".

That can be done in the Service section

[Service]
User=pi
Comments