Use the Windows built-in MP3 decoder to play sound?

How do I use C or C ++ with an MP3 decoder supposedly built into Windows with Windows Media Player 6.1?

I want to play an mp3 file, regardless of any other third-party library, for example, LAME.DLL.

I updated the question in order to better pick up the answers that I have, since I really liked them. A related question.

+6
source share
2 answers

You can control the audio channel (so that it can play anything, including MP3) using mciSendString http://msdn.microsoft.com/en-us/library/ms709492%28VS.85%29.aspx

Here is an example (it is in C #, but 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

+3
source

Of course. Like many other things in the Windows API, there is more than one way to play .mp3 files. The β€œeasiest” way to do this programmatically is to use DirectShow. MSDN docs even have an example of minimal code on a page called "How to play a file" to get started:

 // Visual C++ example #include <dshow.h> #include <cstdio> // For IID_IGraphBuilder, IID_IMediaControl, IID_IMediaEvent #pragma comment(lib, "strmiids.lib") // Obviously change this to point to a valid mp3 file. const wchar_t* filePath = L"C:/example.mp3"; int main() { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; IMediaEvent *pEvent = NULL; // Initialize the COM library. HRESULT hr = ::CoInitialize(NULL); if (FAILED(hr)) { ::printf("ERROR - Could not initialize COM library"); return 0; } // Create the filter graph manager and query for interfaces. hr = ::CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); if (FAILED(hr)) { ::printf("ERROR - Could not create the Filter Graph Manager."); return 0; } hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); // Build the graph. hr = pGraph->RenderFile(filePath, NULL); if (SUCCEEDED(hr)) { // Run the graph. hr = pControl->Run(); if (SUCCEEDED(hr)) { // Wait for completion. long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); // Note: Do not use INFINITE in a real application, because it // can block indefinitely. } } // Clean up in reverse order. pEvent->Release(); pControl->Release(); pGraph->Release(); ::CoUninitialize(); } 

Make sure you read the DirectShow documentation to get an idea of ​​what should happen in the correct DirectShow application.


To "load" multimedia data into a chart, you need to implement IAsyncReader . Fortunately, the Windows SDK contains a sample that implements IAsyncReader called CAsyncReader . The sample reads the media file into the memory buffer, then uses CAsyncReader to stream data to the graph. It may be what you want. On my machine, the sample is located in the folder C:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\multimedia\directshow\filters\async .

+9
source

Source: https://habr.com/ru/post/901434/


All Articles