Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Audio does not work if run from cron or systemd
Forum Updated to NodeBB v4.3 + New Features

Audio does not work if run from cron or systemd

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 557 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • M Mark81

      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.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 Maybe your app is started before the sound daemon is started?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Mark81 Maybe your app is started before the sound daemon is started?

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @jsulm I don't think this is the problem because even if I systemctl start myservice.service manually the behavior is the same.

        jsulmJ 1 Reply Last reply
        0
        • M Mark81

          @jsulm I don't think this is the problem because even if I systemctl start myservice.service manually the behavior is the same.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mark81 Then please do some debugging!
          What does

          systemctl status myservice
          

          output?

          What does

          journalctl -u myservice -b
          

          output?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Mark81 Then please do some debugging!
            What does

            systemctl status myservice
            

            output?

            What does

            journalctl -u myservice -b
            

            output?

            M Offline
            M Offline
            Mark81
            wrote on last edited by
            #5

            @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 or systemd they were not set.
            Right now I just set all of them, like the output of env.

            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 :)

            O 1 Reply Last reply
            0
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • M Mark81

                @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 or systemd they were not set.
                Right now I just set all of them, like the output of env.

                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 :)

                O Offline
                O Offline
                Omega200
                wrote on last edited by
                #7

                @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

                M 1 Reply Last reply
                0
                • O Omega200

                  @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

                  M Offline
                  M Offline
                  Mark81
                  wrote on last edited by Mark81
                  #8

                  @Omega200 I've just exported all the variables I saw with env... I don't have here the script but it's trivial: type env, copy and paste the output inside a script and prepend export on each line.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    volanin
                    wrote on last edited by volanin
                    #9

                    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

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved