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 codeplayaudio.h
@
#ifndef PLAYAUDIO_H
#define PLAYAUDIO_H#include <QWidget>
class QPushButton;
class playAudio : public QWidget
{
Q_OBJECTpublic:
playAudio(QWidget *parent = 0);public slots:
void playSound();private:
QPushButton *play;
};#endif // PLAYAUDIO_H
@playaudio.cpp
@
#include "playaudio.h"
#include <QtGui>playAudio::playAudio(QWidget *parent) :
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"));
}
void playAudio::playSound()
{}
@main.cpp
@
#include <QtGui/QApplication>
#include "playaudio.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
playAudio w;
w.show();return a.exec();
}
@ -
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.
-
In fact they do use phonon...
Huge thread about it: http://lists-archives.org/kde-devel/24844-multiple-sounds-with-phonon.html
-
Ah,
The problem I've mentioned on that thread has been solved by using pulseaudio API's directly. But I do not recommend that =)