Results 1 to 2 of 2

Thread: Pausing a thread while waiting that phonon play a sound file

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Pausing a thread while waiting that phonon play a sound file

    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:

    Qt Code:
    1. void MyClass::onTimer()
    2. {
    3. timer->stop();
    4. //..code..
    5. currentFrame = GetCameraFrame();
    6. if( userIsRecognized(frame) )
    7. {
    8. emit sig_userRecognized();
    9. }
    10. turnOffTheCamera();
    11. //.. more code..
    12. timer->start(5);
    13. }
    To copy to clipboard, switch view to plain text mode 
    in the slot connected to the sig_userRecognized() signal basically I do something and I play a file using phonon so:

    Qt Code:
    1. void MyClass::onUserRecognized()
    2. {
    3. //some code
    4. mediaObject->setCurrentSource( Phonon::MediaSource("./sounds/file.wav") );
    5. mediaObject->play();
    6. //more code
    7. }
    To copy to clipboard, switch view to plain text mode 
    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
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pausing a thread while waiting that phonon play a sound file

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Phonon won't play audio file
    By kar in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2010, 01:41
  2. Phonon, play sound on key press
    By ale6111 in forum Qt Programming
    Replies: 0
    Last Post: 1st August 2010, 16:18
  3. How to play a sound from a resource file?
    By Asperamanca in forum Newbie
    Replies: 3
    Last Post: 21st July 2010, 17:28
  4. Replies: 6
    Last Post: 23rd December 2009, 10:45
  5. Phonon Cannot Play Sound (without Error)
    By padawan in forum Qt Programming
    Replies: 5
    Last Post: 16th September 2009, 15:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.