DShow enables playback of an avi Video (including personal explanations and comments) and dshowavi

Source: Internet
Author: User

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}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.