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

zhaozj2021-02-16  57

Browse, play, pause, close the four-button corresponding event response function is as follows:

Void CPlayWnddlg :: OnbnclicKedBrowsebutton ()

{

CfileDialog Dlgfile (True, Null, Null,

OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,

"Movie Files (* .avi; *. Mpg; *. Mpeg) | /

* .avi; *. mpg; *. MPEG | /

Audio Files (* .wav; * mp3; *. Mpa; *. Mpu; *. Au) | /

* .wav; *. mp3; *. mpa; *. mpu; *. au | /

MIDI

Files (* .mid; *. Midi; *. Rmi) | /

* .mid; *. midi; *. RMI | | ", this)

IF (DLGFILE.DOMODAL () == iDok)

{

M_StrMediafile = DLGFILE.GETPATHNAME ();

Getdlgitem (IDC_MEDIAFILE_EDIT) -> setWindowText; M_StrMediafile;

}

Else

Return;

CoCreateInstance (CLSID_FILTERGRAPH, NULL, CLSCTX_INPROC, IID_IGRAPHBUILDER, (Void **) & m_pgraph);

HRESULT HR = m_pgraph-> renderfile (CA2W (M_StrMediafile), NULL

IF (Failed (HR))

{

Char szmsg [200];

AMGETERRORTEXT (HR, SZMSG, SIZEOF (SZMSG));

AfxMessageBox (SZMSG);

}

// Specify a parent form

IvideoWindow * pvidwin = null;

m_pgraph-> queryinterface (IID_IVideoWindow, (void **) & pvidwin);

PVIDWIN-> PUT_OWNER (OAHWND) M_HWND);

PVIDWIN-> PUT_WINDOWSTYLE (WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);

CRECT RC;

Getdlgitem (IDC_VW_FRAME) -> getWindowRect (RC);

ScreenToClient (RC);

Pvidwin-> setwindowPosition (rc.left, rc.top, rc.width (), rc.Height ());

/ / Note The event of the Filter Graph Manager is issued in WM_GRAPHNOTIFY (user-defined messages).

m_pgraph-> queryinterface (IID_IMEDIAEVENTEX, (Void **) & m_pevent);

M_PEVENT-> SetNotifyWindow ((OAHWND) M_HWND, WM_GRAPHNOTIFY, 0);

// Set Seeking

m_pgraph-> queryinterface (iid_imediaseeking, (void **) & m_pmediaseeping);

}

Void CPlayWnddlg :: OnbnclicKedPlayButton ()

{

Play ();

}

Void CPlayWnddlg :: OnbnclickedPauseButton ()

{

M_PMediaControl-> pause ();

m_isplaming = true;

Getdlgitem (IDC_Play_Button) -> EnableWindow (TRUE);

Getdlgitem (IDC_PAUSE_BUTTON) -> EnableWindow (false);

void cpplaywnddlg :: OnbnclicKedCancel ()

{

// TODO: Add control notification processing code here

Cleanup ();

ONCANCEL ();

}

8. Add a to WM_GRAPHNOTIFY message, and its response function

Add a message ID to the PlayWnddlg:

#define WM_GraphNotify WM_USER 101

In PlayWnddlg.h, the code is as follows:

// Implement

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 ()

AFX_MSG HRESULT ONGRAPHNOTIFY (WPARAM WPARAM, LPARAM LPARAM);

Private:

IgraphBuilder * m_pgraph;

IMediaControl * m_pmediacontrol;

IMediaEventEx * m_pevent;

PlayWnddlg.cpp, as follows:

ON_BN_CLICKED (IDC_BROWSE_BUTTON, ONBNCLICKEDBROWSEBUTTON)

ON_BN_CLICKED (IDC_PLAY_BUTTON, ONBNCLICKEDPLAYBUTTON)

ON_BN_CLICKED (IDC_PAUSE_BUTTON, ONBNCLICKEDPAUSEBUTTON)

ON_BN_CLICKED (IDCANCANCEL, ONBNCLICKEDCANCEL)

ON_MESSAGE (WM_GRAPHNOTIFY, OONGRAPHNOTIFY)

END_MESSAGE_MAP ()

The implementation is as follows:

HRESULT CPLAYWNDDLG :: ONGRAPHNOTIFY (WPARAM WPARAM, LPARAM LPARAM)

{

Long Levcode, LPARAM1, LPARAM2;

HRESULT HR;

While (hr = m_pevent-> getEvent (& Levcode, & lParam1, & lparam2, 0), succeeded (hr))

{

HR = m_pevent-> FreeEventParams (Levcode, LPARAM1, LPARAM2);

IF ((EC_COMPLETE == Levcode) || (EC_USERABORT == Levcode))

{

"" End of the Media File !! ./ N ");

STOP ();

// cleanup ();

Break;

}

}

Return HR;

}

There is a need to request the source code with me.

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

New Post(0)