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

Last change on this file was 138, checked in by roman, 11 years ago

better readability with V macro

  • Property svn:keywords set to Id
File size: 1.7 KB
RevLine 
[133]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
[138]14#define V(x) ATLVERIFY(SUCCEEDED(x))
15
[133]16int _tmain(int argc, _TCHAR* argv[])
17{
18        static LPCTSTR g_pszPath = _T("F:\\Music\\Cher - Walking In Memphis.mp3");
[138]19        V(CoInitialize(NULL));
[133]20        {
21                CComPtr<IGraphBuilder> pGraphBuilder;
[138]22                V(pGraphBuilder.CoCreateInstance(CLSID_FilterGraph));
[133]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;
[138]27                        V(pBaseFilter.CoCreateInstance(CLSID_WMAsfReader));
[133]28                        CComQIPtr<IFileSourceFilter> pFileSourceFilter = pBaseFilter;
29                        ATLASSERT(pFileSourceFilter);
[138]30                        V(pFileSourceFilter->Load(CT2COLE(g_pszPath), NULL));
31                        V(pGraphBuilder->AddFilter(pBaseFilter, NULL));
[133]32                        CComPtr<IEnumPins> pEnumPins;
[138]33                        V(pBaseFilter->EnumPins(&pEnumPins));
[133]34                        CComPtr<IPin> pPin;
35                        ATLVERIFY(pEnumPins->Next(1, &pPin, NULL) == S_OK);
[138]36                        V(pGraphBuilder->Render(pPin));
[133]37                #else
[138]38                        V(pGraphBuilder->RenderFile(CT2CW(g_pszPath), NULL)));
[133]39                #endif
40                CComQIPtr<IMediaControl> pMediaControl = pGraphBuilder;
41                CComQIPtr<IMediaEvent> pMediaEvent = pGraphBuilder;
42                ATLASSERT(pMediaControl && pMediaEvent);
[138]43                V(pMediaControl->Run());
[133]44                LONG nEventCode = 0;
[138]45                V(pMediaEvent->WaitForCompletion(INFINITE, &nEventCode));
[133]46        }
47        CoUninitialize();
48        return 0;
49}
50
Note: See TracBrowser for help on using the repository browser.