播放.wav与QSound (Qt)没有声音存在
play .wav with QSound (Qt) no sound exist
我尝试使用QSound::play
在Qt中播放。wav文件
我试过这个代码:
QSound::play("airplane.wav");
构建时没有错误,但运行时没有声音?!
这给我敲响了警钟,所以我找到了用来处理声音的代码。我们的平台是Windows,所以这是适合我们的。我把这些都写进了玩家课。我给自己的笔记说,QSound需要平台格式的绝对路径(通过检查QSound代码找到)。试着像这样获取文件路径
// (note the "sSoundPath" variable is set to where we store our sound files).
static const QString sSoundPath("./resources/sounds/");
其他地方…
// QSound wants absolute paths, in platform format
QFileInfo fileInfo(soundFile);
if (fileInfo.isRelative())
{
// we assume one of our own sound files in a relative path
fileInfo.setFile(sSoundPath + soundFile);
fileInfo.makeAbsolute();
}
if (!fileInfo.exists())
{
return false;
}
mSoundFile = QDir::toNativeSeparators(fileInfo.filePath());
现在你可以继续并尝试播放声音文件
我在一个类似的问题上花了无数天。基本上,我发现QSound不支持44100 Hz采样率的波文件。查看我在QT5上的发现QSound不能播放所有的波文件
旁注,QSound不支持QT资源,如果你正在使用一个。一种解决方法是将资源复制到一个文件中,然后使用QSound从硬盘驱动器播放该文件。
相关文章:
- C++模板来检查友元函数的存在
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- Xaudio2在更改缓冲区或循环时弹出声音
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 如何检查QList中是否存在值
- 如何更改'a'声音?
- 根据某个函数是否存在启用模板
- 如何将分支添加到已存在的TTree:ROOT
- 播放.wav与QSound (Qt)没有声音存在