Thinking Different





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Dshow_player_sample.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
 
#include "stdafx.h"
#include <DShow.h>
#include <iostream>
#include <locale>
#pragma comment(lib, "Strmiids")
 
using namespace std;
 
int _tmain(int argc, _TCHAR* argv[])
{
    _wsetlocale(LC_ALL, L"korean");
 
    IGraphBuilder *pGraph = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent *pEvent = NULL;
 
    HRESULT hr = CoInitialize(NULL);
    if(FAILED(hr))
    {
        wcout << L"COM 초기화 에러" << endl;
        exit(0);
    }
 
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_SERVER, IID_IGraphBuilder, (void**)&pGraph);
    if(FAILED(hr))
    {
        wcout << L"DD instance crate error" << endl;
        exit(0);
    }
 
    hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
    if(FAILED(hr))
    {
        wcout << L"MediaControl 생성 에러" << endl;
        exit(0);
    }
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void**)&pEvent);
    if(FAILED(hr))
    {
        wcout << L"MediaEvent 생성 에러" << endl;
        exit(0);
    }
    
    wchar_t str[] = L"c:\\한일의 토익 Writing 기본해법01.wmv";
    hr = pGraph->RenderFile(str, NULL);
    if(SUCCEEDED(hr))
    {
        wcout << L"Play Title : " << str << endl;
        if(SUCCEEDED(pControl->Run()))
        {
            long ev;
            pEvent->WaitForCompletion(INFINITE, &ev);
        }
    } else { 
        wcout << L"File Open Error" << endl; 
    }
 
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
 
    CoUninitialize();
 
    return 0;
}
 


간단히 DirectShow를 이용한 동영상 플레이어 간단 샘플을 소개하였다. 해당 코드는 ms dshow html도움말에 제동된 소스를 토대로 작성되었음