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.
Code:
{
if(e
->type
() == QEvent::KeyPress) {
music->play();
music->seek(0);
}
return ui->textEdit->eventFilter(o, e);
}
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.
Re: Phonon stops playing after a while
Code:
{
if(e
->type
() == QEvent::KeyPress) {
music->play();
music->seek(0);
}
return ui->textEdit->eventFilter(o, e);
}
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:
Code:
{
if(e
->type
() == QEvent::KeyPress) {
music->play();
music->seek(0);
}
}
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)?
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:
Code:
int count = 0;
{
if(e
->type
() == QEvent::KeyPress) {
music->play();
music->seek(0);
count++;
if(count == 30){
music->stop();
count = 0;
}
}
return ui->textEdit->eventFilter(o, e);
}