【发布时间】:2016-08-12 10:21:11
【问题描述】:
在 Windows 7 台式机和笔记本电脑上使用 Qt 5.5.1。
我只能听到嗡嗡声,没有别的。请指导。
链接到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 这样的外部链接
-
@TheIndependentAquarius ,如果这很重要,我在 Windows 7 上运行 Qt5.6.1 的笔记本电脑上进行了尝试,完全没有问题。 . .
-
那么您是否尝试更新 QT,因为 Mike 显然正在运行更新版本?我认为它很重要的可能性很小,但这是一个消除过程,然后才会有解决方案。