//========================================================================
//TITLE:
// CMedia更新至v1.4.3
//AUTHOR:
// norains
//DATE:
// Friday 27-July-2007
//Environment:
// EVC4.0 + Windows CE 5.0 Standard SDK
//========================================================================
相对v1.2.0版本进行的改进:
1.增加GetMediaProperty函数获得的属性,增加如下属性:llDuration,llAvailableEarliest,llAvailableLatest.
2.增加如下函数:SetRate(),GetRate(),GetPositionCurrent(),SetPositionCurrent() ,GetDisplayMode()
3.改进之前一些函数的HRESULT值返回BOOL值的判定方法
4.增加SetVideoWindow()一个参数,以设置可以在窗口的任意位置为起点播放视频
5.改进SetDisplayMode()函数,当窗口句柄为空时,设置播放区域为0,并返回FALSE
6.改进SetNotifyWindow()函数,令其能够接收普通的窗口消息
7.Open()的参数改为const类型,更符合实际意义
v1.2.0版本及相关用法见:http://blog.youkuaiyun.com/norains/archive/2007/05/14/1609118.aspx
我们来看看具体更新了哪些功能:
1.MEDIAPROPERTY
增加了llDuration,llAvailableEarliest,llAvailableLatest属性,分别代表影片的时间长度,最早的可拖拽的时间位置,最早的可拖拽的时间位置.这个属性可以用在GetMediaProperty()函数中.
2.SetRate(),GetRate()
SetRate()设置当前的播放速率,"1"为正常速率,"2"即为两倍速,以此类推.
GetRate()获取当前播放的速率.
3.GetPositionCurrent(),SetPositionCurrent()
GetPositionCurrent():获取当前的时间位置,返回的时间值以100ns为基本单位.
SetPositionCurrent():设置播放的时间位置,该范围必须是llAvailableEarliest和llAvailableLatest之间的数值.
4.GetDisplayMode()
该函数用来获取当前的播放模式.
v1.4.3的完整代码如下:
/ //
// Media.h:interfacefortheCMediaclass.
//
// Version:
// 1.4.3
// Date:
// 2007.07.19
/ /
#ifndefMEDIA_H
#define MEDIA_H
#include < mmsystem.h >
#include < streams.h >
// --------------------------------------------------------------------
// Macrodefine
// Thevolumevalue
#define MAX_VOLUME0
#define MIN_VOLUME-10000
// Thebalancevalue
#define MAX_BALANCE10000
#define MIN_BALANCE-10000
// Theflagmeansthattheareaisthewholewindow
const RECTRC_WHOLE_WINDOWN_AREA = { 0 , 0 , 0 , 0 };
// --------------------------------------------------------------------
// Enumvalue
enum DISPLAYMODE
{
// Fittotheplaywindowsize.Howwide(height)thewindowis,how
// isthemove.Keepaspectratio.
DISP_FIT,
// Notsupport.Stretchtotheplaywindowsize.Don'tkeeptheaspectratio.
DISP_STRETCH,
// Fullscreenplay.
DISP_FULLSCREEN,
// Whenthesizeofvideoissmallerthantheplaywindow,itdisplayes
// asthevideosize.Ifit'sbigger,itjustliketheDISP_FITmode.
DISP_NATIVE
};
// --------------------------------------------------------------------
// Themediafileproperty
typedef struct
{
// Thevolumerangeis–10,000to0.
// Divideby100togetequivalentdecibelvalue(forexample–10,000=–100dB).
LONGlVolume;
// Thevaluefrom–10,000to10,000indicatingthestereobalance
// AswiththeVolumeproperty,unitscorrespondto.01decibels(multipliedby–1whenplBalanceisapositivevalue).
// Forexample,avalueof1000indicates–10dBontherightchanneland–90dBontheleftchannel.
LONGlBalance;
// Widthofthevideo
LONGlWidth;
// Heightofthevideo
LONGlHeight;
// Approximatebitrate
LONGlBitRate;
// Thelengthoftimethatthemediastreamwillplay.
// Thedurationassumesnormalplaybackspeed,anditisthereforeunaffectedbytherate
LONGLONGllDuration;
// Earliesttimethatcanbeefficientlyseekedto.
LONGLONGllAvailableEarliest;
// Latesttimethatcanbeefficientlyseekedto
LONGLONGllAvailableLatest;
}MEDIAPROPERTY, * PMEDIAPROPERTY;
// --------------------------------------------------------------------
class CMedia
{
public :
DISPLAYMODEGetDisplayMode();
BOOLSetPositionCurrent(LONGLONGllPos);
BOOLGetPositionCurrent(LONGLONG * pllPos);
BOOLGetRate( double * pdRate);
BOOLSetRate( double dRate);
BOOLGetEvent(LONG * plEvCode,LONG * plParam1,LONG * plParam2);
BOOLSetNotifyWindow(HWNDhWnd,UINTwMsg, long lInstanceData);
BOOLSetVolume(LONGlVolume,LONGlBalance = 0 );
BOOLSetDisplayMode(DISPLAYMODEmode);
BOOLGetMediaProperty(PMEDIAPROPERTYpOutProperty);
static CMedia * GetInstance();
void Close();
BOOLCheckVisibility();
BOOLSetVideoWindow(HWNDhWndVideo, const RECT & rcDisp = RC_WHOLE_WINDOWN_AREA);
BOOLOpen( const TCHAR * pcszFileName);
BOOLStop();
BOOLPause();
BOOLPlay();
virtual ~ CMedia();
protected :
CMedia();
// Collectionofinterfaces
IGraphBuilder * m_pGB;
IMediaControl * m_pMC;
IMediaEventEx * m_pME;
IVideoWindow * m_pVW;
IBasicAudio * m_pBA;
IBasicVideo * m_pBV;
IMediaSeeking * m_pMS;
TCHARm_szFileName[MAX_PATH];
HWNDm_hWndVideo; // Thewindowplayvideo
HWNDm_hWndNotify; // Thewindownotify
BOOLm_bExitThrd;
BOOLm_bThrdRunning;
static CMedia * m_pInstance;
DISPLAYMODEm_DispMode;
DWORDm_dwCapability;
RECTm_rcDisp;
};
#endif // #ifndefMEDIA_H
/ //
// Media.cpp:implementationoftheCMediaclass.
//
/ /
#include " stdafx.h "
#include " Media.h "
// ========================================================================================================
// Linkthe.lib
// Thelibalsoiscopyfrom"(InstallDir)WINCE500PUBLICDIRECTXSDKLIB"
#pragma comment(lib,"Ole32.lib")
#ifdefCPU_X86EM
#pragma comment(lib,"./lib/X86em/Strmiids.lib")
#pragma comment(lib,"./lib/X86em/Strmbase.lib")
#endif
#ifdefCPU_MIPSII
#pragma comment(lib,"./lib/MIPSII/Strmiids.lib")
#pragma comment(lib,"./lib/MIPSII/Strmbase.lib")
#endif
#ifdefCPU_ARM4I
#pragma comment(lib,"./lib/ARM4I/Strmiids.lib")
#pragma comment(lib,"./lib/ARM4I/Strmbase.lib")
#endif
// ========================================================================================================
// ----------------------------------------------------------------------------------------------
// Macrodefine
// Defaultplaymode
#define DEFAULT_DISPLAY_MODEDISP_NATIVE
// ----------------------------------------------------------------------
// Initialize
CMedia * CMedia::m_pInstance = NULL;
// ------------------------------------------------------------------------
/ /
// Construction/Destruction
/ /
CMedia::CMedia():
m_pGB(NULL),
m_pMC(NULL),
m_pME(NULL),
m_pVW(NULL),
m_pBA(NULL),
m_pBV(NULL),
m_pMS(NULL),
m_hWndVideo(NULL),
m_bExitThrd(TRUE),
m_bThrdRunning(FALSE),
m_DispMode(DEFAULT_DISPLAY_MODE),
m_hWndNotify(NULL),
m_rcDisp(RC_WHOLE_WINDOWN_AREA)
{
memset(m_szFileName, 0 , sizeof (m_szFileName));
}
CMedia:: ~ CMedia()
{
if (m_pInstance != NULL)
{
deletem_pInstance;
m_pInstance = NULL;
}
}
// ------------------------------------------------------------
// Description:
// Playthemediafile
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// -------------------------------------------------------------
BOOLCMedia::Play()
{
// Runthegraphtoplaythemediafile
if (m_pMC == NULL)
{
return FALSE;
}
return SUCCEEDED(m_pMC -> Run());
}
// ------------------------------------------------------------
// Description:
// Pause.
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// -------------------------------------------------------------
BOOLCMedia::Pause()
{
if (m_pMC == NULL)
{
return FALSE;
}
return SUCCEEDED(m_pMC -> Pause());
}
// ------------------------------------------------------------
// Description:
// Stop.
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// -------------------------------------------------------------
BOOLCMedia::Stop()
{
if (m_pMC == NULL || m_pMS == NULL)
{
return FALSE;
}
HRESULThr;
hr = m_pMC -> Stop();
SetPositionCurrent( 0 );
return SUCCEEDED(hr);
}
// --------------------------------------------------------------------------
// Description:
// Openthemediafile.Whensucceedincallingthefunction,
// youshouldcalltheClose()toreleasetheresource
//
// -------------------------------------------------------------------------
BOOLCMedia::Open( const TCHAR * pcszFileName)
{
BOOLbResult = FALSE;
if (_tcslen(pcszFileName) >= MAX_PATH)
{
goto END;
}
else
{
_tcscpy(m_szFileName,pcszFileName);
// Checkthefileexisting
HANDLEhdFile = CreateFile(m_szFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL,NULL);
if (hdFile == INVALID_HANDLE_VALUE)
{
// Thefiledoesn'texist
goto END;
}
else
{
CloseHandle(hdFile);
}
}
// InitializeCOM
if (CoInitializeEx(NULL,COINIT_MULTITHREADED) != S_OK)
{
goto END;
}
// GettheinterfaceforDirectShow'sGraphBuilder
if (CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,( void ** ) & m_pGB) != S_OK)
{
goto END;
}
// Havethegraphconstructitstheappropriategraphautomatically
if (m_pGB -> RenderFile(m_szFileName,NULL) != NOERROR)
{
goto END;
}
// QueryInterfaceforDirectShowinterfaces
if (m_pGB -> QueryInterface(IID_IMediaControl,( void ** ) & m_pMC) != NOERROR)
{
goto END;
}
if (m_pGB -> QueryInterface(IID_IMediaEventEx,( void ** ) & m_pME) != NOERROR)
{
goto END;
}
if (m_pGB -> QueryInterface(IID_IMediaSeeking,( void ** ) & m_pMS) != NOERROR)
{
goto END;
}
// Queryforvideointerfaces,whichmaynotberelevantforaudiofiles
if (m_pGB -> QueryInterface(IID_IVideoWindow,( void ** ) & m_pVW) != NOERROR)
{
goto END;
}
if (m_pGB -> QueryInterface(IID_IBasicVideo,( void ** ) & m_pBV) != NOERROR)
{
goto END;
}
if (CheckVisibility() == FALSE)
{
// Itjustbetheaudiofile,anddon'tneedvideofilter.
// Relinquishownership(IMPORTANT!)afterhiding
if (m_pVW != NULL)
{
m_pVW -> put_Visible(OAFALSE);
m_pVW -> put_Owner(NULL);
}
if (m_pBV != NULL)
{
m_pBV -> Release();
m_pBV = NULL;
}
if (m_pVW != NULL)
{
m_pVW -> Release();
m_pVW = NULL;
}
}
// Queryforaudiointerfaces,whichmaynotberelevantforvideo-onlyfiles
if (m_pGB -> QueryInterface(IID_IBasicAudio,( void ** ) & m_pBA) != NOERROR)
{
goto END;
}
// Setplaymode
SetDisplayMode(m_DispMode);
// Getthecapabilitiesofthemediafile.
m_pMS -> GetCapabilities( & m_dwCapability);
bResult = TRUE;
END:
if (bResult == FALSE)
{
// Releasetheresource
Close();
}
return bResult;
}
// ------------------------------------------------------------
// Description:
// Thismethodsetsanowningparentforthevideowindow.
//
// Parameters:
// hWnd:[in]Handleofnewownerwindow.
// rcDisp:[in]Thedisplayarea.Iftheparameterisnotset,
// itwillbesetasRC_WHOLE_WINDOWN_AREAwhichmeansthai
// thewholewindowisfordisplayingthevideo.
//
// ----------------------------------------------------------
BOOLCMedia::SetVideoWindow(HWNDhWndVideo, const RECT & rcDisp)
{
m_hWndVideo = hWndVideo;
m_rcDisp = rcDisp;
if (m_pVW == NULL)
{
return FALSE;
}
if (FAILED(m_pVW -> put_Owner((OAHWND)hWndVideo)))
{
return FALSE;
}
if (FAILED(m_pVW -> put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN)))
{
return FALSE;
}
// Setplaymodeinordertonotifythedisplayedarea
return SetDisplayMode(m_DispMode);
}
// ------------------------------------------------------------
// Description:
// Checkthefilevisibility
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// Parameters:
// TRUE:Video
// FALSE:It'snotthevideo
//
// ------------------------------------------------------------
BOOLCMedia::CheckVisibility()
{
if ( ! m_pVW)
{
// NoVideoWindowinterface.Assumingaudio/MIDIfileorunsupportedvideocodec
return FALSE;
}
if ( ! m_pBV)
{
// NoBasicVideointerface.Assumingaudio/MIDIfileorunsupportedvideocodec.
return FALSE;
}
// Ifthisisanaudio-onlyclip,get_Visible()won'twork.
//
// Also,ifthisvideoisencodedwithanunsupportedcodec,
// wewon'tseeanyvideo,althoughtheaudiowillworkifitis
// ofasupportedformat.
long lVisible;
return SUCCEEDED(m_pVW -> get_Visible( & lVisible));
}
// ------------------------------------------------------------
// Description:
// ReleasetheresourcewhichopenedintheOpen()
//
// ------------------------------------------------------------
void CMedia::Close()
{
// Relinquishownership(IMPORTANT!)afterhiding
if (m_pVW != NULL)
{
m_pVW -> put_Visible(OAFALSE);
m_pVW -> put_Owner(NULL);
}
if (m_pMC != NULL)
{
m_pMC -> Release();
m_pMC = NULL;
}
if (m_pME != NULL)
{
m_pME -> SetNotifyWindow(NULL,NULL,NULL);
m_pME -> Release();
m_pME = NULL;
}
if (m_pMS != NULL)
{
m_pMS -> Release();
m_pMS = NULL;
}
if (m_pBV != NULL)
{
m_pBV -> Release();
m_pBV = NULL;
}
if (m_pBA != NULL)
{
m_pBA -> Release();
m_pBA = NULL;
}
if (m_pVW != NULL)
{
m_pVW -> Release();
m_pVW = NULL;
}
if (m_pGB != NULL)
{
m_pGB -> Release();
m_pGB = NULL;
}
// FinishedwithCOM
memset(m_szFileName, 0 , sizeof (m_szFileName));
CoUninitialize();
}
// ------------------------------------------------------------
// Description:
// Gettheinstanceofobject
//
// ------------------------------------------------------------
CMedia * CMedia::GetInstance()
{
if (m_pInstance == NULL)
{
m_pInstance = new CMedia();
}
return m_pInstance;
}
// ------------------------------------------------------------
// Description:
// Getthemediafileproperty.
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// ------------------------------------------------------------
BOOLCMedia::GetMediaProperty(PMEDIAPROPERTYpOutProperty)
{
MEDIAPROPERTYprop = { 0 };
if (m_pBA == NULL && m_pBV == NULL && m_pMS == NULL)
{
return FALSE;
}
// Gettheaudioproperty
if (m_pBA != NULL)
{
m_pBA -> get_Volume( & prop.lVolume);
m_pBA -> get_Balance( & prop.lBalance);
}
// Getthevideoproperty
if (CheckVisibility() == TRUE && m_pBV != NULL)
{
m_pBV -> get_BitRate( & prop.lBitRate);
m_pBV -> GetVideoSize( & prop.lWidth, & prop.lHeight);
}
// Gettheseekingproperty
if (m_pMS != NULL)
{
m_pMS -> GetDuration( & prop.llDuration);
m_pMS -> GetAvailable( & prop.llAvailableEarliest, & prop.llAvailableLatest);
}
* pOutProperty = prop;
return TRUE;
}
// ------------------------------------------------------------
// Description:
// Setthedisplaymode.
// Whenyoucallthefunction,youshouldcallSetVideoWindow()before.
// Iftheparentwindows(m_hWndVideo)isNULL,thedisplayareawouldbesettozero.
//
// ------------------------------------------------------------
BOOLCMedia::SetDisplayMode(DISPLAYMODEmode)
{
if (m_pVW == NULL)
{
return FALSE;
}
if (m_hWndVideo == NULL)
{
m_pVW -> put_Left( 0 );
m_pVW -> put_Top( 0 );
m_pVW -> put_Width( 0 );
m_pVW -> put_Height( 0 );
return FALSE;
}
m_DispMode = mode;
if (mode == DISP_FULLSCREEN)
{
m_pVW -> put_FullScreenMode(OATRUE);
}
else
{
// Restoretothenormalmode
m_pVW -> put_FullScreenMode(OAFALSE);
RECTrcWnd = m_rcDisp;
if (rcWnd.left == RC_WHOLE_WINDOWN_AREA.left &&
rcWnd.top == RC_WHOLE_WINDOWN_AREA.top &&
rcWnd.right == RC_WHOLE_WINDOWN_AREA.right &&
rcWnd.bottom == RC_WHOLE_WINDOWN_AREA.bottom)
{
GetClientRect(m_hWndVideo, & rcWnd);
}
LONGlWndWidth = rcWnd.right - rcWnd.left;
LONGlWndHeight = rcWnd.bottom - rcWnd.top;
MEDIAPROPERTYprop = { 0 };
GetMediaProperty( & prop);
if (mode == DISP_FIT || mode == DISP_NATIVE)
{
LONGlDispLeft,lDispTop,lDispWidth,lDispHeight;
if (mode == DISP_NATIVE && lWndWidth >= prop.lWidth && lWndHeight >= prop.lHeight)
{
lDispLeft = (lWndWidth - prop.lWidth) / 2 + rcWnd.left;
lDispTop = (lWndHeight - prop.lHeight) / 2 + rcWnd.top;
lDispWidth = prop.lWidth;
lDispHeight = prop.lHeight;
}
else
{
if (prop.lWidth * lWndHeight > lWndWidth * prop.lHeight)
{
lDispWidth = lWndWidth;
lDispHeight = (LONG)(( float )lDispWidth / ( float )prop.lWidth * prop.lHeight);
lDispLeft = rcWnd.left;
lDispTop = (lWndHeight - lDispHeight) / 2 + rcWnd.top;
}
else if (prop.lWidth * lWndHeight < lWndWidth * prop.lHeight)
{
lDispHeight = lWndHeight;
lDispWidth = (LONG)(( float )lDispHeight / ( float )prop.lHeight * prop.lWidth);
lDispLeft = (lWndWidth - lDispWidth) / 2 + rcWnd.left;
lDispTop = rcWnd.top;
}
else
{
lDispWidth = lWndWidth;
lDispHeight = lWndHeight;
lDispLeft = rcWnd.left;
lDispTop = rcWnd.top;
}
}
m_pVW -> put_Left(lDispLeft);
m_pVW -> put_Top(lDispTop);
m_pVW -> put_Width(lDispWidth);
m_pVW -> put_Height(lDispHeight);
}
else if (mode == DISP_STRETCH)
{
m_pVW -> put_Left(rcWnd.left);
m_pVW -> put_Top(rcWnd.top);
m_pVW -> put_Width(lWndWidth);
m_pVW -> put_Height(lWndHeight);
}
}
return TRUE;
}
// ------------------------------------------------------------
// Description:
// Setthevolume.
// Whenyoucallthefunction,youshouldcallOpen()before.
//
// Parameters:
// lVolume:[in]Thevolume(amplitude)oftheaudiosignal.
// Rangeis–10,000to0.
// lBalance:[in]Thebalancefortheaudiosignal.Defaultvalueis0.
// Thevaluefrom–10,000to10,000indicatingthestereobalance.
//
// ------------------------------------------------------------
BOOLCMedia::SetVolume(LONGlVolume,LONGlBalance)
{
if (m_pBA == NULL)
{
return FALSE;
}
if (lVolume < MIN_VOLUME && lVolume > MAX_VOLUME && lBalance < MIN_BALANCE && lBalance > MAX_BALANCE)
{
return FALSE;
}
m_pBA -> put_Volume(lVolume);
m_pBA -> put_Balance(lBalance);
return TRUE;
}
// ----------------------------------------------------------------------
// Description:
// Registersawindowthatwillhandlethenotifiedmessagewhenaspecifiedeventoccursandsomewindowmessage
//
// Parameters:
// hWnd:[in]Handleofwindowtonotify.PassNULLtostopnotification.
// wMsg:[in]Windowmessagetobepassedasthenotification.
// lInstanceData:[in]Value(instancedata)tobepassedasthelParamparameterforthelMsgmessage.
//
// Remarks:
// WhenthenotifiedwindowreceivethewMsgasthenotification,youcouldgettheeventcode.
// Thefollowcodesshowthatprocess:
//
// // "WM_GRAPHNOTIFY"istheuser-definenotifiedmessage
// caseWM_GRAPHNOTIFY:
// {
// LONGevCode,evParam1,evParam2;
//
// // "m_pMedia"istheinstanceoftheCMedia
// if(m_pMedia->GetEvent(&evCode,&evParam1,&evParam2)==TRUE)
// {
// // Checktheeventcode
// if(evCode==EC_COMPLETE)
// {
// // Dosomething
// }
// }
// return0;
// }
//
// Theeventcodeisasfollow:
// EC_ACTIVATEAnaudioorvideorendererislosingorgainingactivation.
// EC_BUFFERING_DATAThebufferingstatusischanging.
// EC_CLOCK_CHANGEDThefiltergraphhaschangedfromonereferenceclocktoanother.
// EC_COMPLETEAlldatahasbeenrendered.
// EC_DRM_LEVELNotifieswhencontentprotectedbydigitalrightsmanagement(DRM)requestssomeformofanalogcontentprotection.
// EC_END_OF_SEGMENTNotifiesthatasegmentendhasbeenreached.
// EC_ERROR_STILLPLAYINGAtleastonecalltoRunfailedinanactivefiltergraph.
// Thecurrentstateofanyunderlyingfiltergraphorgraphsisindeterminate;theymightberunning,butsomearealmostcertainlynot.
// EC_ERRORABORTAnerrorforcedtheterminationofarequestedoperation.
// EC_FULLSCREEN_LOSTThevideorendererisswitchingoutoffull-screenmode.
// EC_NEED_RESTARTThecurrentgraphmustbestoppedandrestarted.
// EC_NOTIFY_WINDOWPassthewindowhandlearoundduringpinconnection.
// EC_OLE_EVENTAfilterispassingatextstringtotheapplication.
// EC_OPENING_FILETheopenfilestatusischanging.
// EC_PALETTE_CHANGEDThevideopalettehaschanged.
// EC_QUALITY_CHANGETheplaybackqualityhaschanged.
// EC_REPAINTArepaintisrequired.
// EC_SEGMENT_STARTEDNotifiesthatanewsegmenthasbeenstarted.
// EC_SHUTTING_DOWNThefiltergraphisstartingtoshutdown.
// DirectShowpassesthisnotificationtoanyplug-indistributorsthatsupporttheIMediaEventSinkinterface.
// EC_STARVATIONOneofthefilters(usuallyaparserorfilesourcefilter)isnotreceivingenoughdata.
// Bydefault,thefiltergraphmanagerwillpauseallrunningfiltersandthenreturntonormaloperationwhenenoughdataisavailable.
// EC_STREAM_CONTROL_STARTEDThestartingreferencetimefromanearliercalltoIAMStreamControl::StartAtpassed.
// EC_STREAM_CONTROL_STOPPEDThestoppingreferencetimefromanearliercalltoIAMStreamControl::StopAtpassed.
// EC_STREAM_ERROR_STILLPLAYINGThestreamisstillplaying,butshouldnotbeplaying.
// EC_STREAM_ERROR_STOPPEDThestreamhasstopped,butshouldnothavestopped.
// EC_TIMETherequestedreferencetimeoccurred.
// EC_USERABORTAuserhasforcedtheterminationofarequestedoperation.
// EC_VIDEO_SIZE_AR_CHANGEDThesizeoraspectratioofthenativevideohaschanged.
// EC_VIDEO_SIZE_CHANGEDThesizeofthenativevideohaschanged.
// EC_WINDOW_DESTROYEDThevideorenderer'sfilterisbeingremovedordestroyed.
//
//
//
// DirectShowpassesthefollowingmessagestothewindowspecifiedbythehWndparameter,
// ifandwhentheapplicationgeneratesthem:
// WM_KEYDOWN
// WM_KEYUP
// WM_LBUTTONDBLCLK
// WM_LBUTTONDOWN
// WM_LBUTTONUP
// WM_MBUTTONDBLCLK
// WM_MBUTTONDOWN
// WM_MBUTTONUP
// WM_MOUSEACTIVATE
// WM_MOUSEMOVE
// WM_RBUTTONDBLCLK
// WM_RBUTTONDOWN
// WM_RBUTTONUP
// -----------------------------------------------------------------------------
BOOLCMedia::SetNotifyWindow(HWNDhWnd,UINTwMsg, long lInstanceData)
{
if (m_pME == NULL)
{
return FALSE;
}
HRESULThr;
hr = m_pME -> SetNotifyWindow((OAHWND)hWnd,wMsg,lInstanceData);
if (FAILED(hr))
{
return FALSE;
}
if (CheckVisibility() == TRUE && m_pVW != NULL)
{
hr = m_pVW -> put_MessageDrain((OAHWND)hWnd);
}
return SUCCEEDED(hr);
}
// ----------------------------------------------------------------------
// Description:
// Thismethodretrievesthenotificationevent.
//
// -----------------------------------------------------------------------
BOOLCMedia::GetEvent(LONG * plEvCode,LONG * plParam1,LONG * plParam2)
{
if (m_pME == NULL)
{
return FALSE;
}
LONGevCode,evParam1,evParam2;
if (SUCCEEDED(m_pME -> GetEvent( & evCode, & evParam1, & evParam2, 0 )) == TRUE)
{
* plEvCode = evCode;
* plParam1 = evParam1;
* plParam2 = evParam2;
// Spinthroughtheevents
m_pME -> FreeEventParams(evCode,evParam1,evParam2);
}
else
{
return FALSE;
}
return TRUE;
}
// ----------------------------------------------------------------------
// Description:
// Thismethodsetsanewplaybackrate.
//
// Parameters
// dRate:[in]Newrate,where1isthenormalrate,2istwiceasfast,andsoon.
// -----------------------------------------------------------------------
BOOLCMedia::SetRate( double dRate)
{
if (m_pMS == NULL)
{
return FALSE;
}
return SUCCEEDED(m_pMS -> SetRate(dRate));
}
// ----------------------------------------------------------------------
// Description:
// Thismethodretrievesthecurrentrate.
//
// Parameters:
// pdRate:[out]Therate
// -----------------------------------------------------------------------
BOOLCMedia::GetRate( double * pdRate)
{
if (m_pMS == NULL)
{
return FALSE;
}
return SUCCEEDED(m_pMS -> GetRate(pdRate));
}
// ----------------------------------------------------------------------
// Description:
// Thismethodretrievesthecurrentpositionintermsofthetotallengthofthemediastream
//
// Parameters:
// pllPos:[out]Currentposition.
// -----------------------------------------------------------------------
BOOLCMedia::GetPositionCurrent(LONGLONG * pllPos)
{
if (m_pMS == NULL)
{
return FALSE;
}
if (m_dwCapability & AM_SEEKING_CanGetCurrentPos == 0 )
{
return FALSE;
}
return SUCCEEDED(m_pMS -> GetCurrentPosition(pllPos));
}
// ----------------------------------------------------------------------
// Description:
// Thismethodsetscurrentpositions
//
// Parameters:
// llPos:[in]Startpositionifstopped,orpositionfromwhichtocontinueifpaused.
// -----------------------------------------------------------------------
BOOLCMedia::SetPositionCurrent(LONGLONGllPos)
{
if (m_pMS == NULL)
{
return FALSE;
}
LONGLONGllCur = 0 ;
if (GetPositionCurrent( & llCur) == TRUE)
{
if ((llCur > llPos) && (m_dwCapability & AM_SEEKING_CanSeekBackwards == 0 ))
{
return FALSE;
}
else if ((llCur < llPos) && (m_dwCapability & AM_SEEKING_CanSeekForwards == 0 ))
{
return FALSE;
}
else if (llCur == llPos)
{
// It'sthecurrentpositon,needn'tset
return TRUE;
}
}
else if ((m_dwCapability & AM_SEEKING_CanSeekBackwards == 0 ) || (m_dwCapability & AM_SEEKING_CanSeekForwards == 0 ))
{
return FALSE;
}
return SUCCEEDED(m_pMS -> SetPositions( & llPos,AM_SEEKING_AbsolutePositioning,NULL,AM_SEEKING_NoPositioning));
}
// ----------------------------------------------------------------------
// Description:
// Thismethodgetcurrentdisplaymode
//
// ----------------------------------------------------------------------
DISPLAYMODECMedia::GetDisplayMode()
{
return m_DispMode;
}