Results 1 to 4 of 4

Thread: Phonon stops playing after a while

  1. #1
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Phonon stops playing after a while

    Hi all

    I'm having problems with Phonon. I've written application which plays some sound on KeyPressed event. But after a minute or less the volume of that sound is reduced and then it completly stops, sometimes it just stops. I've never used Phonon before so I think that my code is wrong. Can you help me out with this.

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if(e->type() == QEvent::KeyPress)
    4. {
    5. music->play();
    6. music->seek(0);
    7. }
    8. return ui->textEdit->eventFilter(o, e);
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Phonon stops playing after a while

    I need to add that this sound is really short (less then second) and it's repeating al over every time user press keyboard button. Everything is ok, but then suddenly it just stop playing, and when it occurs I get different sound in my headphones, it sounds like when you unplug headphones from your PC, something like that.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,387
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Phonon stops playing after a while

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if(e->type() == QEvent::KeyPress)
    4. {
    5. music->play();
    6. music->seek(0);
    7. }
    8. return ui->textEdit->eventFilter(o, e);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I think the problem is that you are preventing the MainWindow from handling events as it should. Look at the example in QObject::eventFilter(). You want something like that:

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if(e->type() == QEvent::KeyPress)
    4. {
    5. music->play();
    6. music->seek(0);
    7. }
    8. return QMainWindow::eventFilter( 0, e );
    9. }
    To copy to clipboard, switch view to plain text mode 

    Playing a note every time the user presses a key anywhere in your app might get pretty annoying after a while, don't you think? You sure you don't want to restrict this to specific widgets within your app (like the text edit, for example)?

  4. #4
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Phonon stops playing after a while

    That was my first aproach, but with same results, so I tried with this return ui->textEdit->eventFilter(o, e); and with that sound lasts longer, but still it's not enough. So I made silly but effective solution, it's not very good but it works better then any of previous solutions:

    Qt Code:
    1. int count = 0;
    2. bool MainWindow::eventFilter(QObject *o, QEvent *e)
    3. {
    4. if(e->type() == QEvent::KeyPress)
    5. {
    6. music->play();
    7. music->seek(0);
    8. count++;
    9. if(count == 30){
    10. music->stop();
    11. count = 0;
    12. }
    13. }
    14. return ui->textEdit->eventFilter(o, e);
    15. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Playing MP3 with Qt/Phonon libs
    By tcampos in forum Qt Programming
    Replies: 0
    Last Post: 9th May 2012, 11:36
  2. can't get o/p by playing mp3 file in Phonon
    By dibyendu in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 13:09
  3. Phonon MediaObject playback of audio file stops early
    By mortoray in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2010, 12:37
  4. Playing only some channels with Phonon
    By jfrousval in forum Qt Programming
    Replies: 0
    Last Post: 10th March 2009, 13:30
  5. Phonon video not playing
    By SidGBF in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2008, 15:30

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.