_franko_
22nd November 2010, 18:10
Hi there!
This is my first post on this great forum ;)
I found here many good answers and examples. But I cannot find solution for this one...
I'm writing a quite big project with network programming and i have to play sound when my client connect and send some message to server.
First step which i made was to create an object of my class which encapsulate QAudioOutput and just use function (QAudioOutput::start()) from examples which shows how to play sound using this Qt class. That works ok but when client send more same message in short time not all sounds were played. So i decided to use QThread subclass to hear multiple sounds at once. Unfortunately the sound wasn't heard.
Can someone could help me with this problem?
I post here en example of my other short app in which i tried join thread and QAudioOutput. Same result - i don't hear sound as if file wasn't played or not send to audio device from the thread.
PlayFile::PlayFile(QString fn) : format(0), info(new QAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDe vice())), ao(0), file(0) {
filename = fn;
setQuality();
printSupportedFeatures();
// setObjectName("mythread");
}
void PlayFile::setQuality() {
if(!format)
format = new QAudioFormat();
format->setCodec("audio/pcm");
format->setChannels(1);
format->setFrequency(11025);
// format->setFrequency(22050);
format->setSampleSize(8);
}
void PlayFile::sPlayFile() {
// qDebug("Odtwarzanie dzwieku...");
if(!file) {
file = new QFile(filename);
file->open(QIODevice::ReadOnly);
}
if(!ao)
ao = new QAudioOutput(*info, *format);
ao->start(file);
qDebug("error: %d", ao->error());
}
void PlayFile::run() {
// qDebug("Watek %s", this->objectName().toStdString().c_str());
sPlayFile();
// qDebug("buffer %d", ao->bufferSize());
// qDebug("bytes %d", ao->bytesFree());
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PlayFile* pf = new PlayFile("./alarm.wav");
// using this slot to start thread doesn't produce sound on output.. why?
pf->start();
// when i use this fuction (slot) i hear the sound
// pf->sPlayFile();
MainWindow w;
w.show();
return a.exec();
}
Please help me to correct this problem.
This is my first post on this great forum ;)
I found here many good answers and examples. But I cannot find solution for this one...
I'm writing a quite big project with network programming and i have to play sound when my client connect and send some message to server.
First step which i made was to create an object of my class which encapsulate QAudioOutput and just use function (QAudioOutput::start()) from examples which shows how to play sound using this Qt class. That works ok but when client send more same message in short time not all sounds were played. So i decided to use QThread subclass to hear multiple sounds at once. Unfortunately the sound wasn't heard.
Can someone could help me with this problem?
I post here en example of my other short app in which i tried join thread and QAudioOutput. Same result - i don't hear sound as if file wasn't played or not send to audio device from the thread.
PlayFile::PlayFile(QString fn) : format(0), info(new QAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDe vice())), ao(0), file(0) {
filename = fn;
setQuality();
printSupportedFeatures();
// setObjectName("mythread");
}
void PlayFile::setQuality() {
if(!format)
format = new QAudioFormat();
format->setCodec("audio/pcm");
format->setChannels(1);
format->setFrequency(11025);
// format->setFrequency(22050);
format->setSampleSize(8);
}
void PlayFile::sPlayFile() {
// qDebug("Odtwarzanie dzwieku...");
if(!file) {
file = new QFile(filename);
file->open(QIODevice::ReadOnly);
}
if(!ao)
ao = new QAudioOutput(*info, *format);
ao->start(file);
qDebug("error: %d", ao->error());
}
void PlayFile::run() {
// qDebug("Watek %s", this->objectName().toStdString().c_str());
sPlayFile();
// qDebug("buffer %d", ao->bufferSize());
// qDebug("bytes %d", ao->bytesFree());
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PlayFile* pf = new PlayFile("./alarm.wav");
// using this slot to start thread doesn't produce sound on output.. why?
pf->start();
// when i use this fuction (slot) i hear the sound
// pf->sPlayFile();
MainWindow w;
w.show();
return a.exec();
}
Please help me to correct this problem.