source: trunk/Utilities/Miscellaneous/PlayMp3File/PlayMp3File.cpp @ 133

Last change on this file since 133 was 133, checked in by roman, 10 years ago
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2012
3// Created by Roman Ryltsov roman@alax.info
4//
5// $Id: PlayMp3File.cpp 133 2012-10-14 09:30:55Z 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
14int _tmain(int argc, _TCHAR* argv[])
15{
16        static LPCTSTR g_pszPath = _T("F:\\Music\\Cher - Walking In Memphis.mp3");
17        ATLVERIFY(SUCCEEDED(CoInitialize(NULL)));
18        {
19                CComPtr<IGraphBuilder> pGraphBuilder;
20                ATLVERIFY(SUCCEEDED(pGraphBuilder.CoCreateInstance(CLSID_FilterGraph)));
21                // 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:
22                //       with a large headers the files might be rejected; the longer versions takes all .MP3 files
23                #if TRUE
24                        CComPtr<IBaseFilter> pBaseFilter;
25                        ATLVERIFY(SUCCEEDED(pBaseFilter.CoCreateInstance(CLSID_WMAsfReader)));
26                        CComQIPtr<IFileSourceFilter> pFileSourceFilter = pBaseFilter;
27                        ATLASSERT(pFileSourceFilter);
28                        ATLVERIFY(SUCCEEDED(pFileSourceFilter->Load(CT2COLE(g_pszPath), NULL)));
29                        ATLVERIFY(SUCCEEDED(pGraphBuilder->AddFilter(pBaseFilter, NULL)));
30                        CComPtr<IEnumPins> pEnumPins;
31                        ATLVERIFY(SUCCEEDED(pBaseFilter->EnumPins(&pEnumPins)));
32                        CComPtr<IPin> pPin;
33                        ATLVERIFY(pEnumPins->Next(1, &pPin, NULL) == S_OK);
34                        ATLVERIFY(SUCCEEDED(pGraphBuilder->Render(pPin)));
35                #else
36                        ATLVERIFY(SUCCEEDED(pGraphBuilder->RenderFile(CT2CW(g_pszPath), NULL)));
37                #endif
38                CComQIPtr<IMediaControl> pMediaControl = pGraphBuilder;
39                CComQIPtr<IMediaEvent> pMediaEvent = pGraphBuilder;
40                ATLASSERT(pMediaControl && pMediaEvent);
41                ATLVERIFY(SUCCEEDED(pMediaControl->Run()));
42                LONG nEventCode = 0;
43                ATLVERIFY(SUCCEEDED(pMediaEvent->WaitForCompletion(INFINITE, &nEventCode)));
44        }
45        CoUninitialize();
46        return 0;
47}
48
Note: See TracBrowser for help on using the repository browser.