PlayFile
::PlayFile(QString fn
) : format
(0), info
(new QAudioDeviceInfo
(QAudioDeviceInfo
::defaultOutputDevice())), 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
);
}
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[])
{
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();
}
PlayFile::PlayFile(QString fn) : format(0), info(new QAudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice())), 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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks