Kill aplay inside QT application
-
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..
-
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..
@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. -
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. -
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.@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. -
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.