DShow enables playback of an avi Video (including personal explanations and comments) and dshowavi
This project is the console C ++ code under win32 (do not forget to configure the DShow Library)
1 // movie_test.cpp: defines the entry point of the console application. 2 // 3 # include "stdafx. h "4 # include <DShow. h> 5 6 # pragma comment (lib, "strmiids. lib ") // You can also add 7 8 int _ tmain (int argc, _ TCHAR * argv []) 9 {10 IGraphBuilder * pGraph = NULL in the attribute; // icon Manager interface 11 IMediaControl * pControl = NULL; // media Controller Interface 12 IMediaEvent * pEvent = NULL; // media event interface 13 14 // initialize com Library 15 HRESULT hr = CoInitialize (NULL); 16 if (FAILED (hr )) 17 {18 printf ("failed to initialize com component \ n"); 19 return-1; 20} 21 22 // create filter linked list manager 23 hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) & pGraph); 24 if (FAILED (hr) 25 {26 printf ("FAILED to initialize com component \ n "); 27 return-1; 28} 29 30 // QueryInterface for querying media control and media events 31 hr = pGraph-> QueryInterface (IID_IMediaControl, (void **) & pControl ); 32 hr = pGraph-> QueryInterface (IID_IMediaEvent, (void **) & pEvent); 33 34 // create a linked list, here, you can change the name of the file to be played 35 hr = pGraph-> RenderFile (L "E: \ DXSDK 9.0B \ Samples \ Media \ ruby. avi ", NULL); 36 if (SUCCEEDED (hr) 37 {38 // Run the linked list 39 hr = pControl-> Run (); 40 if (SUCCEEDED (hr )) 41 {42 // wait until playback ends 43 long evCode; 44 pEvent-> WaitForCompletion (INFINITE, & evCode); 45 // remember: in actual applications, the infinite id cannot be used, because he will be unsure of the blocking program 46} 47} 48 49 // Release all resources 50 pControl-> Release (); 51 pEvent-> Release (); 52 pGraph-> Release (); 53 CoUninitialize (); 54 printf ("this is example \ n"); 55 return 0; 56}