要使用(在這種情況下)DirectShow的在Windows中發揮.mp3
文件,你只需要:播放音頻流通過在C的Windows API ++
#include <dshow.h>
#include <cstdio>
// For IID_IGraphBuilder, IID_IMediaControl, IID_IMediaEvent
#pragma comment(lib, "strmiids.lib")
const wchar_t* filePath = L"C:/Users/Public/Music/Sample Music/Sleep Away.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();
}
我不能找到一種方法,有這樣的事情,但要能夠發揮.asx
代替,例如像:http://listen.radiotunes.com/public5/solopiano.asx
在MSDN我只能想辦法在C#中製作表格應用程序,將在表單中的WindowsMediaPlayer控制做到這一點。
任何想法?
嗯,好吧,這就是了。我試圖[這](http://msdn.microsoft.com/en-us/library/windows/desktop/dd564579(v = vs.85).aspx)---但我如何使用該控制在C++中的示例[這裏](http://msdn.microsoft.com/en-us/library/windows/desktop/dd564119(v = vs.85).aspx)(也就是我認爲的JScript)... – Alex 2014-12-06 14:33:32
WM sdk也應包含一個C++ api。你應該檢查文檔和標題。 – 2014-12-06 19:52:25
是的,'IWMPPlayer'可以很好地完成這項工作。謝謝:) – Alex 2014-12-06 20:44:23