Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Kill aplay inside QT application

Kill aplay inside QT application

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 736 Views
  • 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.
  • H Offline
    H Offline
    hakanaktan
    wrote on last edited by
    #1

    Hi,
    i am playing wav files by running code below using QProcess.

    void WorkerSoundPlayer::PlaySound(QString file)
    {
    QProcess process;
    process.start("aplay " + file);
    process.waitForFinished();
    }

    i can not stop sound using "killall aplay" command. if i connect device as root from ssh and write this command , it kills aplay.
    But it does not work inside Qt application and gives error:
    "killall: aplay: no process killed"

    thanx in advance..

    jsulmJ 1 Reply Last reply
    0
    • H hakanaktan

      Hi,
      i am playing wav files by running code below using QProcess.

      void WorkerSoundPlayer::PlaySound(QString file)
      {
      QProcess process;
      process.start("aplay " + file);
      process.waitForFinished();
      }

      i can not stop sound using "killall aplay" command. if i connect device as root from ssh and write this command , it kills aplay.
      But it does not work inside Qt application and gives error:
      "killall: aplay: no process killed"

      thanx in advance..

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

      @hakanaktan Can you show your code where you're trying to kill it?
      In the code you posted you wait until the process finishes - if you're calling kill after waitForFinished() it will not work as aplay already finished.
      Also, why do you use aplay to play WAV files? You can do that with Qt without starting new processes.

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

      1 Reply Last reply
      1
      • H Offline
        H Offline
        hakanaktan
        wrote on last edited by
        #3

        i am trying to kill aplay in the deconstructor of worker class.

        WorkerSoundPlayer::~WorkerSoundPlayer()
        {
        system("killall -9 aplay");
        }

        i am destroying the class in the deconstrcutor of form until sound playing finishes, before waitforFinished completes.
        i tried Phonon library and QAudioOutput class to run sound files asynchronus but i get some crash error "I/O Possible" if i close the thread until sound finishes, so i walked this way.

        jsulmJ 1 Reply Last reply
        0
        • H hakanaktan

          i am trying to kill aplay in the deconstructor of worker class.

          WorkerSoundPlayer::~WorkerSoundPlayer()
          {
          system("killall -9 aplay");
          }

          i am destroying the class in the deconstrcutor of form until sound playing finishes, before waitforFinished completes.
          i tried Phonon library and QAudioOutput class to run sound files asynchronus but i get some crash error "I/O Possible" if i close the thread until sound finishes, so i walked this way.

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

          @hakanaktan Well, as I said you call kill when aplay has already finished playing, so there is nothing to kill.

          process.waitForFinished() <-- This is a blocking call!
          

          Don't call waitForFinished().

          Why do you use threads to play WAV files?! There is really no need to do so. You over-engineer things it looks...
          QAudioOutput is already asynchronous.

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

          1 Reply Last reply
          1
          • H Offline
            H Offline
            hakanaktan
            wrote on last edited by
            #5

            QAudioOutput is actually synchronous cause it blocks GUI when started.
            Anyway i solved the problem. i call the kill command from GUI not from thread class.
            it worked this way.

            thanks for your attention.

            1 Reply Last reply
            0

            • Login

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