从 Visual C 播放 mp3 的最简单方法

发布于 2024-08-17 13:35:17 字数 300 浏览 5 评论 0 原文

几年前,我围绕 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

感悟人生的甜 2024-08-24 13:35:17

PlaySound() 本身就支持 MP3,只要它嵌入在 WAV 文件中即可。
人们没有意识到 WAV 是一种容器格式。

下载 ffmpeg 实用程序来转换标头并保留编解码器:

ffmpeg -i input.mp3 -c copy -f wav embedded_mp3.wav

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:

ffmpeg -i input.mp3 -c copy -f wav embedded_mp3.wav
傾城如夢未必闌珊 2024-08-24 13:35:17

您可以使用 DirectShow,但它不再是 DirectX 的一部分,也可以依赖第三方库,例如 Bass, FMod, mpg123 甚至 libwmp3

如果您不想再使用 DirectShow(但如果现有代码继续工作,为什么还要更改?),您可以使用 MCI

mciSendString("open la_chenille.mp3 type mpegvideo alias song1", NULL, 0, 0); 
mciSendString("play song1", NULL, 0, 0);
mciSendString("close song1", NULL, 0, 0);

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:

mciSendString("open la_chenille.mp3 type mpegvideo alias song1", NULL, 0, 0); 
mciSendString("play song1", NULL, 0, 0);
mciSendString("close song1", NULL, 0, 0);
抽个烟儿 2024-08-24 13:35:17

IGraphBuilder::RenderFile是播放任何音频文件的简单方法。

IGraphBuilder::RenderFile is an easy way to play any audio file.

娇俏 2024-08-24 13:35:17

你可以使用 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.

勿挽旧人 2024-08-24 13:35:17

如果您不想支付任何许可证并想在内部进行,请解析您的 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

智商已欠费 2024-08-24 13:35:17

你可以看看BASS。这是一个简单易用的音频库,免费供非商业用途。

You could have a look at BASS. It's a simple to use audio library, free for noncommercial use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文