在Windows 7桌面和筆記本電腦上使用Qt 5.5.1。通過QAudioOutput播放wav文件時只發出嗡嗡聲
我只能聽到嗡嗡的聲音,沒有別的。請指導。
鏈接到wav文件,我想 - https://www.dropbox.com/s/frfy43d8hznptgf/c.wav?dl=0
我與MP3文件也試過這樣。我得到的只是嗡嗡聲。
的可再現的例子:
#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();
}
輸出:
到wav文件的鏈接會很棒。 –
我該怎麼做? @ Jean-FrançoisFabre –
我承認將不得不鏈接到像Dropbox這樣的外部鏈接 –