In the Visual Studio .NET 2003 uses DirectShow to play media files (2)

zhaozj2021-02-16  60

3. Set up an engineering attribute

Project → PlayWnd Properties → Configuration Properties → Links → Enter → Additional Dependencies, Add Library Strmiids.lib and Quartz.lib.

Since the dshow.h header file is used in any DirectShow project, we stdafx.h add to the following:

#include

4. Design dialog, as follows:

IDC_STATIC

Control type

Static text

CAPTION

Media file name:

IDC_MEDIAFILE_EDIT

Control type

Edit Control

IDC_BROWSE_BUTTON

Control type

Button

CAPTION

Browse

IDC_VW_FRAME

Control type

Picture Control

Type

Rectangle

IDC_PLAY_BUTTON

Control type

Button

CAPTION

Play

IDC_PAUSE_BUTTON

Control type

Button

CAPTION

time out

IDCANCEL

Control type

Button

CAPTION

shut down

5.com's initialization and uninstallation,

Modify PlayWnd.cpp Add initialization code (the joined code is expressed in black body, the same below)

Bool cpplayWndapp :: InitInstance ()

{

// If a list of applications running on Windows XP specifies

// Use ComctL32.dll version 6 or higher to enable visual mode,

// requires INITCOMMONCONTROLS (). Otherwise, the window will not be created.

INITCOMMONCONTROLS ();

// Initialize COM interface

HRESULT HR = Coinitialize (NULL);

IF (Failed (HR))

{

"Error - Could Not Initialize COM Library./N");

Return False;

}

CWINAPP :: InitInstance ();

AFXENABLECONTROLCONTAINER ();

Modify PlayWnd.cpp Add Uninstall COM code, pay attention to overloading the virtual function EXITINSTANCE

INT CPLAYFILEAPP :: EXIXSTANCE ()

{

// TODO: Add a dedicated code and / or call the base class here

// Turn off COM

Couninitialize ();

Return CWINAPP :: EXITINSTANCE ();

}

6. Define media control member variables

Modify PlayWnddlg.h as follows:

protected:

Hicon M_Hicon;

// Generated message mapping function

Virtual Bool OnInitdialog ();

AFX_MSG Void OnSysCommand (Uint Nid, LParam Lparam);

AFX_MSG void onpaint ();

AFX_MSG HCURSOR ONQUERYDRAGICON ();

Declare_message_map ()

/ / And media control related member variables

Private:

Igraphbuilder * m_pgraph; // g graphbuilder interface provides methods for generating filter graph phase // off

IMediaControl * m_pmediacontrol; // iMediaControl interface provides a way to control flow through filter // GRAPH data streams

IMediaeventex * m_pevent; // iMediaEventEx inherits from iMediaEvent, providing methods for obtaining event messages from // filter graph manager

IMediaseeking * m_pmediaseeking; // iMediaseeping provides a control flow playing location and play // speed method cstring m_StrMediafile; / / The name of the media file currently played

BOOL M_ISPLAYING; / / Current playback status

}

转载请注明原文地址:https://www.9cbs.com/read-21869.html

New Post(0)