Giovanni Bauermeister Giovanni Bauermeister - 27 days ago 10
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.

Description=Voting Machine Launch Service



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


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

That can be done in the Service section