PDA

View Full Version : Pausing a thread while waiting that phonon play a sound file



franco.amato
21st March 2011, 19:58
Hi to all,
In my application I play a sound file when a particular situation occours ( a user is recognized with a biometric system ).
The code is basically executed in a timer event so:


void MyClass::onTimer()
{
timer->stop();
//..code..
currentFrame = GetCameraFrame();
if( userIsRecognized(frame) )
{
emit sig_userRecognized();
}
turnOffTheCamera();
//.. more code..
timer->start(5);
}

in the slot connected to the sig_userRecognized() signal basically I do something and I play a file using phonon so:


void MyClass::onUserRecognized()
{
//some code
mediaObject->setCurrentSource( Phonon::MediaSource("./sounds/file.wav") );
mediaObject->play();
//more code
}
What I would do is pause the onTimer routine 'till the file has finished to play but I don't know how because seems that's played in a separated thread.
Regards

wysota
21st March 2011, 21:41
It's not played in a separate thread. It's just played asynchronously. You can use QEventLoop to wait for a finished() signal from the media object.