Using Qt 5.5.1 on a Windows 7 desktop and a laptop.
I have tried the following program with mp3, wav, flac files. I can only hear the buzzing sound, nothing else. Please guide.
The reproducable example:
#include <QCoreApplication>
#include <QAudioOutput>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QAudioOutput* audioOutpu;
sourceFile.setFileName("c.wav");
bool p
= sourceFile.
open(QIODevice::ReadOnly);
if (p == false)
qDebug() << "no file";
else
qDebug() << "yes file";
QAudioDeviceInfo d1;
QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput);
qDebug() << "======================================================";
qDebug() << l1.first().supportedCodecs();
qDebug() << l1.first().supportedChannelCounts();
qDebug() << l1.first().supportedSampleTypes();
qDebug() << l1.first().supportedSampleRates();
qDebug() << l1.first().supportedSampleSizes();
QAudioFormat desiredFormat1;
desiredFormat1.setChannelCount(2);
desiredFormat1.setByteOrder(QAudioFormat::LittleEndian);
desiredFormat1.setCodec("audio/pcm");
desiredFormat1.setSampleType(QAudioFormat::SignedInt);
desiredFormat1.setSampleRate(44100);
desiredFormat1.setSampleSize(16);
QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
if (!info1.isFormatSupported(desiredFormat1))
{
qWarning() << "Default format not supported, trying to use the nearest.";
desiredFormat1 = info1.preferredFormat();
}
audioOutpu = new QAudioOutput(desiredFormat1);
audioOutpu->setVolume(1.0);
audioOutpu->start(&sourceFile);
qDebug() << "bbbbbbbbbb";
QObject::connect(audioOutpu,
SIGNAL(stateChanged
(QAudio
::State)),
&loop,
SLOT(quit
()));
do {
loop.exec();
} while(audioOutpu->state() == QAudio::ActiveState);
return a.exec();
}
#include <QCoreApplication>
#include <QAudioOutput>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QAudioOutput* audioOutpu;
QFile sourceFile;
sourceFile.setFileName("c.wav");
bool p = sourceFile.open(QIODevice::ReadOnly);
if (p == false)
qDebug() << "no file";
else
qDebug() << "yes file";
QAudioDeviceInfo d1;
QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput);
qDebug() << "======================================================";
qDebug() << l1.first().supportedCodecs();
qDebug() << l1.first().supportedChannelCounts();
qDebug() << l1.first().supportedSampleTypes();
qDebug() << l1.first().supportedSampleRates();
qDebug() << l1.first().supportedSampleSizes();
QAudioFormat desiredFormat1;
desiredFormat1.setChannelCount(2);
desiredFormat1.setByteOrder(QAudioFormat::LittleEndian);
desiredFormat1.setCodec("audio/pcm");
desiredFormat1.setSampleType(QAudioFormat::SignedInt);
desiredFormat1.setSampleRate(44100);
desiredFormat1.setSampleSize(16);
QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
if (!info1.isFormatSupported(desiredFormat1))
{
qWarning() << "Default format not supported, trying to use the nearest.";
desiredFormat1 = info1.preferredFormat();
}
audioOutpu = new QAudioOutput(desiredFormat1);
audioOutpu->setVolume(1.0);
audioOutpu->start(&sourceFile);
qDebug() << "bbbbbbbbbb";
QEventLoop loop;
QObject::connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
do {
loop.exec();
} while(audioOutpu->state() == QAudio::ActiveState);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Output:
Screenshot from 2016-08-16 13:10:31.png
Bookmarks