How to play sound
i am creating a small application that plays sound by clicking "Play Sound". How can i do that.
here is my code
class playAudio : public QWidget
playAudio(QWidget *parent = 0);
#endif // PLAYAUDIO_H
playAudio::playAudio(QWidget *parent) :
QLabel *label = new QLabel(tr("Click Play to Play a Sound"));
play = new QPushButton(tr("Play Sound"));
connect(play, SIGNAL(clicked()), this, SLOT(playSound())); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(label, 0, 0); mainLayout->addWidget(play, 1, 0); setLayout(mainLayout); setWindowTitle(tr("Play Sound"));
int main(int argc, char *argv)
QApplication a(argc, argv);
All it does is play a sound file, it doesn't support pausing or seeking, and it only works with simple formats like WAVE. It's meant mostly for short sound effects.
If you're a linux user:
QSound will not work if your Xorg doesn't use NAS (probably it doesn't use).
Try "QtMultimedia":http://doc.trolltech.com/4.6/qtmultimedia.html module or even Phonon API's.
Somehow I doubt that they use Phonon for all the little sound effects in Linux Qt programs.
Anyway, I never tried QSound, so I don't know if it will work.
In fact they do use phonon...
Huge thread about it: http://lists-archives.org/kde-devel/24844-multiple-sounds-with-phonon.html
The problem I've mentioned on that thread has been solved by using pulseaudio API's directly. But I do not recommend that =)