[Qt-interest] play audio in thread

Nitin Mahajan nitinm76 at yahoo.com
Fri Mar 5 13:09:39 CET 2010


HI!

--- On Fri, 5/3/10, Moises Augusto <jr.jorro at gmail.com> wrote:

> From: Moises Augusto <jr.jorro at gmail.com>
> Subject: [Qt-interest] play audio in thread
> To: qt-interest at trolltech.com
> Date: Friday, 5 March, 2010, 6:17 AM
> Hi all,
> 
> I need to play a small audio in my app. On Linux, I do a
>  the loop in app, and call the run() the thread:
> 
> thread::run() {
>        Phonon::MediaObject *audio
> =
> Phonon::createPlayer(Phonon::MusicCategory,
> 
> Phonon::MediaSource(QDir::homePath() + path_som));
> 
>        audio->play();
>        sleep(intervalo);
>        audio->stop();
> }
> 

If the object you created in new thread is supposed to handle event, and has signals and slots, then you need to run an event loop by calling exec().

In your code, you also need to have a condition at which quit() will be called so that it comes out of event loop in new thread

-Nitin

> in WINDOWS :@ dosen't work. When I put exec() at the end of
> the run(),
> it plays only once. (he does ???). but after the crash
> screen.
> 
> On Linux if you put exec() hangs too.
> 
> I need to touch the thread for wearing a counter in the
> main program.
> 
> The question is: Is there a different way I play the audio?
> Or I
> I'm doing something wrong in the thread so as not to run in
> windows?
> 
> thanks
> 
> Moises
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 


      Get your new Email address!
Grab the Email name you&#39;ve always wanted before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/




More information about the Qt-interest-old mailing list