1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2012 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // $Id: PlayMp3File.cpp 138 2012-10-16 19:32:20Z roman $ |
---|
6 | |
---|
7 | #include "stdafx.h" |
---|
8 | #include <dshow.h> |
---|
9 | #include <dshowasf.h> |
---|
10 | #include <atlcom.h> |
---|
11 | |
---|
12 | #pragma comment(lib, "strmiids.lib") |
---|
13 | |
---|
14 | #define V(x) ATLVERIFY(SUCCEEDED(x)) |
---|
15 | |
---|
16 | int _tmain(int argc, _TCHAR* argv[]) |
---|
17 | { |
---|
18 | static LPCTSTR g_pszPath = _T("F:\\Music\\Cher - Walking In Memphis.mp3"); |
---|
19 | V(CoInitialize(NULL)); |
---|
20 | { |
---|
21 | CComPtr<IGraphBuilder> pGraphBuilder; |
---|
22 | V(pGraphBuilder.CoCreateInstance(CLSID_FilterGraph)); |
---|
23 | // NOTE: A simpler version is good for the files you are sure of that they don't have too much of ID3 tags on the header: |
---|
24 | // with a large headers the files might be rejected; the longer versions takes all .MP3 files |
---|
25 | #if TRUE |
---|
26 | CComPtr<IBaseFilter> pBaseFilter; |
---|
27 | V(pBaseFilter.CoCreateInstance(CLSID_WMAsfReader)); |
---|
28 | CComQIPtr<IFileSourceFilter> pFileSourceFilter = pBaseFilter; |
---|
29 | ATLASSERT(pFileSourceFilter); |
---|
30 | V(pFileSourceFilter->Load(CT2COLE(g_pszPath), NULL)); |
---|
31 | V(pGraphBuilder->AddFilter(pBaseFilter, NULL)); |
---|
32 | CComPtr<IEnumPins> pEnumPins; |
---|
33 | V(pBaseFilter->EnumPins(&pEnumPins)); |
---|
34 | CComPtr<IPin> pPin; |
---|
35 | ATLVERIFY(pEnumPins->Next(1, &pPin, NULL) == S_OK); |
---|
36 | V(pGraphBuilder->Render(pPin)); |
---|
37 | #else |
---|
38 | V(pGraphBuilder->RenderFile(CT2CW(g_pszPath), NULL))); |
---|
39 | #endif |
---|
40 | CComQIPtr<IMediaControl> pMediaControl = pGraphBuilder; |
---|
41 | CComQIPtr<IMediaEvent> pMediaEvent = pGraphBuilder; |
---|
42 | ATLASSERT(pMediaControl && pMediaEvent); |
---|
43 | V(pMediaControl->Run()); |
---|
44 | LONG nEventCode = 0; |
---|
45 | V(pMediaEvent->WaitForCompletion(INFINITE, &nEventCode)); |
---|
46 | } |
---|
47 | CoUninitialize(); |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|