几年前,我围绕 DShow/DSound 编写了一些 util 库,让我可以在 Windows C++ 应用程序中播放 MP3。这仍然是在 C++/MFC 应用程序中执行此操作的常规方法吗?还是 DirectX 的一个区域已被纳入通用 Windows API 中?
动机很简单,我们使用 WAV 的标准 Windows PlaySound 方法,并且希望能够使用类似的简单 API(由 Windows 提供或我们编写的用于包装更复杂功能的东西)来播放 MP3。
编辑:这是一个大型的商业闭源项目。而且我们只想简单地玩东西,花很多钱买一个图书馆是行不通的。
A few years back, I wrote some util library around DShow/DSound to let me play MP3s in a Windows C++ application. Is that still the normal way to do it in a C++/MFC app, or is that an area of DirectX that has been subsumed into the general Windows APIs?
The motivation is simply we use the standard Windows PlaySound method for WAVs, and would like to be able to play MP3s using a similarly simple API, either provided by Windows or something we write to wrap more complex functionality.
EDIT: this is for a large, commercial, closed-source project. And we only want to play things simply, paying a lot for a library won't fly.
发布评论
评论(6)
PlaySound() 本身就支持 MP3,只要它嵌入在 WAV 文件中即可。
人们没有意识到 WAV 是一种容器格式。
下载 ffmpeg 实用程序来转换标头并保留编解码器:
PlaySound() natively supports MP3 as long as it is embedded in a WAV file.
People don't realize that WAV is a container format.
Download the ffmpeg utilities to convert the header and preserve the codec:
您可以使用 DirectShow,但它不再是 DirectX 的一部分,也可以依赖第三方库,例如 Bass, FMod, mpg123 甚至 libwmp3。
如果您不想再使用 DirectShow(但如果现有代码继续工作,为什么还要更改?),您可以使用 MCI:
You can either use DirectShow but it's not part of DirectX anymore or rely on a third-party library like Bass, FMod, mpg123 or even libwmp3.
If you don't want to use DirectShow anymore (but why change if your existing code keeps working?), you can use MCI:
IGraphBuilder::RenderFile是播放任何音频文件的简单方法。
IGraphBuilder::RenderFile is an easy way to play any audio file.
你可以使用 MCI windows 函数,
https://msdn.microsoft.com/en-us/library/ms709626
它可以播放多种音频文件格式,包括 MP3、WAV、MIDI 等。
如果我没记错的话,它不需要 DirectX。
PlaySound 函数可能也适合您。
Youc could use MCI windows functions,
https://msdn.microsoft.com/en-us/library/ms709626
It can play many of audio file formats including MP3, WAV, MIDI etc.
If I recall correctly it does not require DirectX.
The PlaySound function might also work for you.
如果您不想支付任何许可证并想在内部进行,请解析您的 mp3 文件并将其传递给 XAudio2。
您只需执行一次(最多 2-3 小时)即可始终使用。 :P
If you don't want to pay any licence and wanna do in-house, do the parsing of your mp3 file and pass it to XAudio2.
Its a thing that you can do once (2-3 hours at max) and use always. :P
你可以看看BASS。这是一个简单易用的音频库,免费供非商业用途。
You could have a look at BASS. It's a simple to use audio library, free for noncommercial use.