我如何在 C 或 C++ 中使用自 Windows Media Player 6.1 以来 Windows 内置的 MP3 解码器?
我想播放 mp3 文件,而不必依赖任何其他第三方库,例如 LAME.DLL。
我更新了问题以更好地适应我得到的答案,因为我非常喜欢它们。 相关问题。
How do I from C or C++ use the MP3 decoder supposedly built in with Windows since Windows Media Player 6.1?
I want to play an mp3 file without having to depend on any other third party library such as for instance LAME.DLL.
I updated the question to better fit the answers I got, since I liked them a lot. Related question.
发布评论
评论(2)
当然。与 Windows API 中的许多其他功能一样,播放
.mp3
文件的方法不止一种。以编程方式执行此操作的“最简单”方法是使用 DirectShow。 MSDN 文档甚至在一个页面上包含了一个最小的代码示例,该示例被恰当地称为“如何播放文件” ” 开始使用:请务必通读 DirectShow 文档,了解正确的 DirectShow 应用程序中应该发生的情况。
要将媒体数据“馈送到”图表中,您需要实现一个
IAsyncReader
。幸运的是,Windows SDK 包含一个示例,它实现了一个名为的IAsyncReader
CAsyncReader
。该示例将媒体文件读入内存缓冲区,然后使用 CAsyncReader 将数据流式传输到图表中。这可能就是你想要的。在我的计算机上,示例位于文件夹C:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\multimedia\directshow\filters\async
中。Sure. Like lots of other things in the Windows API, there's more than one way to go about playing
.mp3
files. The "easiest" way to do this programmatically is using DirectShow. The MSDN docs even include a minimal code example on a page aptly called "How To Play a File" to get you started:Make sure you read through the DirectShow documentation to get an idea of what's supposed to happen in a proper DirectShow application.
To "feed" media data into a graph, you need to implement a
IAsyncReader
. Fortunately, the Windows SDK includes a sample that implements anIAsyncReader
calledCAsyncReader
. The sample reads a media file into a memory buffer then usesCAsyncReader
to stream the data into the graph. This may be what you want. On my machine the sample is located in the folderC:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\multimedia\directshow\filters\async
.您可以使用 mciSendString http://msdn.microsoft.com/en-us/library/ms709492%28VS.85%29.aspx
下面是一个示例(用 C# 编写,但原理基本相同):
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/152f0149-a62a-446d-a205-91256da7845d
这里在C中也是同样的原理:
< a href="http://www.daniweb.com/software-development/c/code/268167" rel="nofollow">http://www.daniweb.com/software-development/c/code/268167
You can control an audio channel (in order to make it play anything, including MP3) with mciSendString http://msdn.microsoft.com/en-us/library/ms709492%28VS.85%29.aspx
Here's an example (it's in C#, but it's basically the same principle):
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/152f0149-a62a-446d-a205-91256da7845d
Here is the same principle in C:
http://www.daniweb.com/software-development/c/code/268167