Audio does not work if run from cron or systemd
-
Ubuntu 21.10, Qt 6.2.0. In my QML I have a MediaPlayer:
MediaPlayer {
id: mediaPlayer
videoOutput: videoOutput
audioOutput: audioOutput
onErrorOccurred: { console.log(mediaPlayer.errorString) }
}AudioOutput {
id: audioOutput
volume: 1.0
}VideoOutput {
id: videoOutput
anchors.centerIn: parent
width: 1080
height: 1920
}When I execute my application from QtCreator or I run it from command line all works fine and I can hear the audio. Instead when the application is launched by a cron job or by a systemd service, I have no errors but no audio as well.
Both the cron job or the systemd service run as a specified user NOT as root.
-
Ubuntu 21.10, Qt 6.2.0. In my QML I have a MediaPlayer:
MediaPlayer {
id: mediaPlayer
videoOutput: videoOutput
audioOutput: audioOutput
onErrorOccurred: { console.log(mediaPlayer.errorString) }
}AudioOutput {
id: audioOutput
volume: 1.0
}VideoOutput {
id: videoOutput
anchors.centerIn: parent
width: 1080
height: 1920
}When I execute my application from QtCreator or I run it from command line all works fine and I can hear the audio. Instead when the application is launched by a cron job or by a systemd service, I have no errors but no audio as well.
Both the cron job or the systemd service run as a specified user NOT as root.
-
@jsulm I don't think this is the problem because even if I
systemctl start myservice.service
manually the behavior is the same. -
@Mark81 Then please do some debugging!
What doessystemctl status myservice
output?
What does
journalctl -u myservice -b
output?
@jsulm there were no errors there.
I found the problem even if I don't fully understand the details.I had to set the env variables in the script because when starting from
cron
orsystemd
they were not set.
Right now I just set all of them, like the output ofenv
.I'm sure it does not need all, but my knowledge is not enough to select which ones. I can only make blind guesses removing one by one, but it's not very professional :)
-
This post is deleted!
-
@jsulm there were no errors there.
I found the problem even if I don't fully understand the details.I had to set the env variables in the script because when starting from
cron
orsystemd
they were not set.
Right now I just set all of them, like the output ofenv
.I'm sure it does not need all, but my knowledge is not enough to select which ones. I can only make blind guesses removing one by one, but it's not very professional :)
-
@Mark81 I got the same problem as you on raspberry pi 4, got no sound when I run my app as a systemd service. Can you please show your script. thanks
-
This is the only solution that worked for me.
I use systemd to call a script that starts the QT program, and my WebEngineView didn't output audio at all.
After using this solution (exporting all my env variables inside the script before calling the QT program) the problem was solved.
I wanted to go a little further, and after a lot of trial and error, I discovered that the only variable I needed to set was HOME. So, I added this to my script and everything worked.
export HOME=/home/root
Thanks @Mark81