PDA

View Full Version : problem with directshow9



Attapong
27-01-2005, 12:06 AM
When I try to play movie in fullscreen, usually resulting in only sound with no picture. :?: \r\nHelp me please :oops: :oops: :oops: :oops: \r\n\r\n
unit EngineUnit;\r\n\r\ninterface\r\nuses\r\n Windows, Messages,ActiveX,ComObj,SysUtils, Forms, Direct3D9, D3DX9,\r\n D3DApp, D3DFont, D3DUtil, DXUtil,Directshow9, InputDevice;\r\nconst\r\n WM_GRAPHNOTIFY = WM_APP + 1;\r\nType\r\n TEngine = class;\r\n TMOVIEEngine = class\r\n\r\n GraphBuilder&#58; IGraphBuilder;\r\n MediaControl&#58; IMediaControl;\r\n VideoWindow &#58; IVideoWindow;\r\n MediaEvent &#58;IMediaEventEX;\r\n FEngine &#58; TEngine;\r\n private\r\n public\r\n RenderHWD &#58; THandle;\r\n constructor Create;\r\n Destructor Destroy;override;\r\n procedure Render&#40;Filename &#58; String&#41;;\r\n Procedure AssignEngine&#40;Engine &#58; TEngine&#41;;\r\n end;\r\n\r\n TVMR9Graph = class\r\n private\r\n FMediawindow &#58; HWND;\r\n RotId &#58; Integer;\r\n // SRC interfaces array\r\n FilterArray &#58;array &#91;0..10&#93; of IBaseFilter;\r\n // SOUND interfaces\r\n DirectSoundFilter &#58; IBaseFilter;\r\n // GRAPH interfaces\r\n //GraphUnknown &#58; IUnKnow;\r\n GraphBuilder &#58; IGraphBuilder;\r\n FilterGraph &#58; IFilterGraph;\r\n FilterGraph2 &#58; IFilterGraph2;\r\n MediaControl&#58; IMediaControl;\r\n //VideoWindow &#58; IVideoWindow;\r\n MediaEvent &#58; IMediaEvent;\r\n MediaEventEX &#58;IMediaEventEX;\r\n // VMR9 interfaces\r\n VMRBaseFilter &#58; IBaseFilter;\r\n VMRFilterConfig &#58; IVMRFilterConfig9;\r\n VMRMixerBitmap&#58; IVMRMixerBitmap9;\r\n VMRMixerControl&#58; IVMRMixerControl9;\r\n VMRMonitorConfig&#58; IVMRMonitorConfig9;\r\n VMRWindowlessControl&#58; IVMRWindowlessControl9;\r\n // DIRECT3D interfaces\r\n D3DDirect3d&#58; IDirect3D9;\r\n D3DDevice&#58; IDirect3DDevice9;\r\n D3DSurface&#58; IDirect3DSurface9;\r\n public\r\n constructor Create;\r\n Destructor Destroy;override;\r\n function AddToRot&#40;pUnkGraph &#58; IFilterGraph&#41;&#58; HResult;\r\n procedure RemoveFromRot;\r\n function GetPin&#40;pFilter&#58; IBaseFilter; PinDir&#58; TPinDirection; out ppPin&#58; IPin&#41;&#58; HRESULT;\r\n end;\r\n\r\n TEngine = class&#40;CD3DApplication&#41;\r\n m_pFont&#58; CD3DFont; // Font for drawing text\r\n \r\n protected\r\n function OneTimeSceneInit&#58; HRESULT; override;\r\n function AdjustWindowForChange&#58; HRESULT; override;\r\n function InitDeviceObjects&#58; HRESULT; override;\r\n function RestoreDeviceObjects&#58; HRESULT; override;\r\n function InvalidateDeviceObjects&#58; HRESULT; override;\r\n function DeleteDeviceObjects&#58; HRESULT; override;\r\n function Render&#58; HRESULT; override;\r\n function FrameMove&#58; HRESULT; override;\r\n function ConfirmDevice&#40;const pCaps&#58; TD3DCaps9; dwBehavior&#58; DWORD;\r\n adapterFormat&#58; TD3DFormat; backBufferFormat&#58; TD3DFormat&#41;&#58; HRESULT; override;\r\n function FinalCleanup&#58; HRESULT; override;\r\n function CheckForLostFullscreen&#58; HResult;\r\n procedure BuildPresentParamsFromSettings; override;\r\n public\r\n fAppForm&#58; TForm;\r\n m_hwndRenderWindow&#58; HWND;\r\n m_hwndRenderFullScreen&#58; HWND;\r\n Mouse &#58; TMouse;\r\n D3DSurface&#58; IDirect3DSurface9;\r\n constructor Create;\r\n procedure AssignWindowsHandles;\r\n function MsgProc&#40;hWnd&#58; HWND; uMsg&#58; UINT; wParam&#58; WPARAM; lParam&#58; LPARAM&#41;&#58; LRESULT; override;\r\n\r\n end;\r\n\r\nimplementation\r\n\r\nconstructor TVMR9Graph.Create;\r\nvar\r\n i &#58; Integer;\r\nbegin\r\n FMediaWindow&#58;= 0&#123;nil&#125;; &#40;* default VMR9 config*&#41;\r\n &#40;* SRC interfaces*&#41;\r\n for&#123;while&#125; i&#58;=0 to Pred&#40;10&#41; &#123; i++&#125;\r\n do\r\n begin\r\n FilterArray&#91;i&#93;&#58;= Nil;\r\n end;\r\n DirectSoundFilter&#58;= Nil;\r\n //GraphUnknown&#58;= nil;\r\n GraphBuilder&#58;= nil;\r\n FilterGraph&#58;= nil;\r\n FilterGraph2&#58;= nil;\r\n MediaControl&#58;= nil;\r\n MediaEvent&#58;= nil;\r\n MediaEventEx&#58;= nil;\r\n VMRBaseFilter&#58;= nil;\r\n VMRFilterConfig&#58;= nil;\r\n VMRMixerBitmap&#58;= nil;\r\n VMRMixerControl&#58;= nil;\r\n VMRMonitorConfig&#58;= nil;\r\n VMRWindowlessControl&#58;= nil;\r\n D3DDirect3d&#58;= nil;\r\n D3DDevice&#58;= nil;\r\n D3DSurface&#58;= nil;\r\nend;\r\nDestructor TVMR9Graph.Destroy;\r\nVar\r\n i &#58; Integer;\r\n pSrcFilter &#58; IBaseFilter;\r\nbegin\r\n if MediaEventEx<>nil then\r\n begin\r\n MediaEventEx.SetNotifyWindow&#40;0,WM_APP + 1,0&#41;;\r\n end;\r\n &#40;* SRC interfaces*&#41;\r\n for i&#58;=0 to Pred&#40;10&#41; &#123; i++&#125;\r\n do\r\n begin\r\n pSrcFilter &#58;= FilterArray&#91;i&#93;;\r\n if pSrcFilter<>nil then\r\n begin \r\n pSrcFilter._Release;\r\n FilterArray&#91;i&#93;&#58;= nil;\r\n end;\r\n end;\r\n &#40;* SOUND interfaces*&#41;\r\n if DirectSoundFilter<>nil then\r\n begin \r\n DirectSoundFilter._Release;\r\n DirectSoundFilter&#58;= nil;\r\n end;\r\n &#40;* VMR9 interfaces*&#41;\r\n if VMRFilterConfig<>nil then\r\n begin \r\n VMRFilterConfig._Release;\r\n VMRFilterConfig&#58;= nil;\r\n end;\r\n if VMRMixerBitmap<>nil then\r\n begin\r\n VMRMixerBitmap._Release;\r\n VMRMixerBitmap&#58;= nil;\r\n end;\r\n if VMRMixerControl<>nil then\r\n begin\r\n VMRMixerControl._Release;\r\n VMRMixerControl&#58;= nil;\r\n end;\r\n if VMRMonitorConfig<>nil then\r\n begin\r\n VMRMonitorConfig._Release;\r\n VMRMonitorConfig&#58;= nil;\r\n end;\r\n if VMRWindowlessControl<>nil then\r\n begin\r\n VMRWindowlessControl._Release;\r\n VMRWindowlessControl&#58;= nil;\r\n end;\r\n if VMRBaseFilter<>nil then\r\n begin\r\n VMRBaseFilter._Release;\r\n VMRBaseFilter&#58;= nil;\r\n end;\r\n &#40;* GRAPH interfaces*&#41;\r\n if GraphBuilder<>nil then\r\n begin\r\n GraphBuilder._Release;\r\n GraphBuilder&#58;= nil;\r\n end;\r\n if FilterGraph<>nil then\r\n begin\r\n FilterGraph._Release;\r\n FilterGraph&#58;= nil;\r\n end;\r\n if FilterGraph2<>nil then\r\n begin\r\n FilterGraph2._Release;\r\n FilterGraph2&#58;= nil;\r\n end;\r\n if MediaControl<>nil then\r\n begin\r\n MediaControl._Release;\r\n MediaControl&#58;= nil;\r\n end;\r\n if MediaEvent<>nil then\r\n begin\r\n MediaEvent._Release;\r\n MediaEvent&#58;= nil;\r\n end;\r\n if MediaEventEx<>nil then\r\n begin\r\n MediaEventEx._Release;\r\n MediaEventEx&#58;= nil;\r\n end;\r\n &#40;*if GraphUnknown<>0&#123;nil&#125;\r\n then\r\n begin\r\n m_pGraphUnknown.Release&#40;&#41;;\r\n m_pGraphUnknown&#58;= 0&#123;nil&#125;;\r\n end;*&#41;\r\n &#40;* DIRECT3D interfaces*&#41;\r\n if D3DSurface<>nil then\r\n begin\r\n D3DSurface._Release;\r\n D3DSurface&#58;= nil;\r\n end;\r\n if D3DDevice<>nil then\r\n begin\r\n D3DDevice._Release;\r\n D3DDevice&#58;= nil;\r\n end;\r\n if D3DDirect3d<>nil then\r\n begin\r\n D3DDirect3d._Release;\r\n D3DDirect3d&#58;= nil;\r\n end;\r\nend;\r\n\r\nfunction TVMR9Graph.AddToRot&#40;pUnkGraph &#58; IFilterGraph&#41;&#58; HResult;\r\nvar\r\n Moniker&#58; IMoniker;\r\n ROT &#58; IRunningObjectTable;\r\n wsz &#58; WideString;\r\nbegin\r\n result &#58;= GetRunningObjectTable&#40;0, ROT&#41;;\r\n if &#40;result <> S_OK&#41; then exit;\r\n wsz &#58;= format&#40;''FilterGraph %p pid %x'',&#91;pointer&#40;pUnkGraph&#41;,GetCurrentProcessId&#40;&#41;&#93;&#41;;\ r\n result &#58;= CreateItemMoniker&#40;''!'', PWideChar&#40;wsz&#41;, Moniker&#41;;\r\n if &#40;result <> S_OK&#41; then exit;\r\n result &#58;= ROT.Register&#40;0, pUnkGraph, Moniker, RotId&#41;;\r\n Moniker &#58;= nil;\r\nend;\r\n\r\nProcedure TVMR9Graph.RemoveFromRot;\r\nvar\r\n ROT&#58; IRunningObjectTable;\r\nbegin\r\n if &#40;SUCCEEDED&#40;GetRunningObjectTable&#40;0, ROT&#41;&#41;&#41;then\r\n begin\r\n ROT.Revoke&#40;RotId&#41;;\r\n RotId &#58;= -1;\r\n ROT &#58;= nil;\r\n end;\r\nend;\r\n\r\nfunction TVMR9Graph.GetPin&#40;pFilter&#58; IBaseFilter; PinDir&#58; TPinDirection; out ppPin&#58; IPin&#41;&#58; HRESULT;\r\nvar\r\n Enum&#58; IEnumPins;\r\n Found&#58; Cardinal;\r\n Pin&#58; IPin;\r\n PinDirThis &#58; TPinDirection;\r\n iNum &#58; Integer;\r\nbegin\r\n ppPin &#58;= nil;\r\n iNum &#58;= 0;\r\n if not Assigned&#40;pFilter&#41; then\r\n begin\r\n Result &#58;= E_POINTER;\r\n Exit;\r\n end;\r\n\r\n Result &#58;= pFilter.EnumPins&#40;Enum&#41;;\r\n if FAILED&#40;Result&#41; then Exit;\r\n\r\n Result &#58;= E_FAIL;\r\n\r\n while&#40;S_OK = Enum.Next&#40;1, Pin, @Found&#41;&#41; do\r\n begin\r\n Pin.QueryDirection&#40;PinDirThis&#41;;\r\n if &#40;PinDir = PinDirThis&#41; then\r\n begin\r\n if &#40;iNum = 0&#41; then\r\n begin\r\n ppPin &#58;= Pin; // Return the pin''s interface\r\n Result &#58;= S_OK; // Found requested pin, so clear error\r\n break;\r\n end;\r\n inc&#40;iNum&#41;;\r\n end;\r\n Pin &#58;= nil;\r\n end;\r\n Enum &#58;= nil;\r\nend;\r\n\r\nconstructor TEngine.Create;\r\nbegin\r\n inherited;\r\n m_strWindowTitle &#58;= ''Movie Sample By Directshow'';\r\n m_bShowCursorWhenFullscreen &#58;= True;\r\n m_d3dEnumeration.AppUsesDepthBuffer &#58;= True;\r\n\r\n m_pFont &#58;= CD3DFont.Create&#40;''Arial'', 12, D3DFONT_BOLD&#41;;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; OneTimeSceneInit&#40;&#41;\r\n// Desc&#58; Called during initial app startup, this function performs all the\r\n// permanent initialization.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.OneTimeSceneInit&#58; HRESULT;\r\nbegin\r\n // Set cursor to indicate that user can move the object with the mouse\r\n&#123;$IFDEF WIN64&#125;\r\n SetClassLongPtr&#40;m_hWnd, GCLP_HCURSOR, LONG_PTR&#40;LoadCursor&#40;0, IDC_SIZEALL&#41;&#41;&#41;;\r\n&#123;$ELSE&#125;\r\n SetClassLong&#40;m_hWnd, GCL_HCURSOR, LoadCursor&#40;0, IDC_SIZEALL&#41;&#41;;\r\n&#123;$ENDIF&#125;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; FrameMove&#40;&#41;\r\n// Desc&#58; Called once per frame, the call is the entry point for animating\r\n// the scene.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.FrameMove&#58; HRESULT;\r\nbegin\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; Render&#40;&#41;\r\n// Desc&#58; Called once per frame, the call is the entry point for 3d\r\n// rendering. This function sets up render states, clears the\r\n// viewport, and renders the scene.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.Render&#58; HRESULT;\r\nbegin\r\n // Clear the viewport\r\n m_pd3dDevice.Clear&#40;0, nil, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,\r\n D3DCOLOR_RGBA&#40;0,0,0,0&#41;, 1.0, 0&#41;;\r\n\r\n // Begin the scene\r\n if SUCCEEDED&#40;m_pd3dDevice.BeginScene&#41; then\r\n begin\r\n // Output statistics\r\n m_pFont.DrawText&#40;2, 0, D3DCOLOR_ARGB&#40;255,255,255,0&#41;, m_strFrameStats&#41;;\r\n m_pFont.DrawText&#40;2, 20, D3DCOLOR_ARGB&#40;255,255,255,0&#41;, m_strDeviceStats&#41;;\r\n m_pFont.DrawText&#40;2, 40, D3DCOLOR_ARGB&#40;255,255,0,250&#41;, ''Click Mouse Left to play Movie and Click Right to stop''&#41;;\r\n m_pFont.DrawText&#40;2, 60, D3DCOLOR_ARGB&#40;255,0,0,250&#41;, ''Press Esc Button to Window Mode''&#41;;\r\n\r\n // End the scene\r\n m_pd3dDevice.EndScene;\r\n end;\r\n\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; AdjustWindowForChange&#40;&#41;\r\n// Desc&#58; Adjusts the window properties for windowed or fullscreen mode\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.AdjustWindowForChange&#58; HRESULT;\r\nbegin\r\n if &#40;m_bWindowed&#41; then\r\n begin\r\n ShowWindow&#40;m_hwndRenderFullScreen, SW_HIDE&#41;;\r\n m_hWnd&#58;= m_hwndRenderWindow;\r\n end else\r\n begin\r\n if IsIconic&#40;m_hwndRenderFullScreen&#41; then\r\n ShowWindow&#40;m_hwndRenderFullScreen, SW_RESTORE&#41;;\r\n\r\n ShowWindow&#40;m_hwndRenderFullScreen, SW_SHOW&#41;;\r\n m_hWnd&#58;= m_hwndRenderFullScreen;\r\n end;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; InitDeviceObjects&#40;&#41;\r\n// Desc&#58; Initialize scene objects.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.InitDeviceObjects&#58;HRESULT;\r\nVar\r\n hr &#58; HResult;\r\nbegin\r\n // Initialize the font''s internal textures\r\n m_pFont.InitDeviceObjects&#40;m_pd3dDevice&#41;;\r\n hr &#58;= m_pd3dDevice.CreateOffscreenPlainSurface&#40;m_d3dsdBa ckBuffer.Width,m_d3dsdBackBuffer.Height,\r\n m_d3dsdBackBuffer.Format,D3DPOOL_SYSTEMMEM,D3DSurf ace,NIL&#41;;\r\n if hr = E_FAIL then\r\n begin\r\n Application.MessageBox&#40;''Can not create a Direct3d surface'',\r\n ''Movie Render'', MB_ICONERROR or MB_OK&#41;;\r\n end;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; RestoreDeviceObjects&#40;&#41;\r\n// Desc&#58; Initialize scene objects.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.RestoreDeviceObjects&#58; HRESULT;\r\nbegin\r\n m_pFont.RestoreDeviceObjects;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; InvalidateDeviceObjects&#40;&#41;\r\n// Desc&#58;\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.InvalidateDeviceObjects&#58; HRESULT;\r\nbegin\r\n m_pFont.InvalidateDeviceObjects;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; DeleteDeviceObjects&#40;&#41;\r\n// Desc&#58; Called when the app is exiting, or the device is being changed,\r\n// this function deletes any device dependent objects.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.DeleteDeviceObjects&#58; HRESULT;\r\nbegin\r\n m_pFont.DeleteDeviceObjects;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; ConfirmDevice&#40;&#41;\r\n// Desc&#58; Called during device initialization, this code checks the device\r\n// for some minimum set of capabilities\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.ConfirmDevice&#40;const pCaps&#58; TD3DCaps9; dwBehavior&#58; DWORD;\r\n adapterFormat&#58; TD3DFormat; backBufferFormat&#58; TD3DFormat&#41;&#58; HRESULT;\r\nbegin\r\n Result&#58;= E_FAIL;\r\n\r\n // Need to support post-pixel processing &#40;for alpha blending&#41;\r\n if FAILED&#40;m_pD3D.CheckDeviceFormat&#40;pCaps.AdapterOrdin al, pCaps.DeviceType,\r\n adapterFormat, D3DUSAGE_RENDERTARGET or D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,\r\n D3DRTYPE_SURFACE, backBufferFormat&#41;&#41;\r\n then Exit;\r\n\r\n // Only D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, or D3DFMT_X8R8G8B8 format\r\n // are supported for fullscreen GDI mode.\r\n if not &#40;backBufferFormat in &#91;D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8&#93;&#41; then Exit;\r\n\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; FinalCleanup&#40;&#41;\r\n// Desc&#58; Called before the app exits, this function gives the app the chance\r\n// to cleanup after itself.\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.FinalCleanup&#58; HRESULT;\r\nbegin\r\n SAFE_DELETE&#40;m_pFont&#41;;\r\n Result&#58;= S_OK;\r\nend;\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; MsgProc&#40;&#41;\r\n// Desc&#58; Message proc function to handle user input\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.MsgProc&#40;hWnd&#58; HWND; uMsg&#58; UINT; wParam&#58; WPARAM; lParam&#58; LPARAM&#41;&#58; LRESULT;\r\nbegin\r\n Result&#58;= inherited MsgProc&#40;hWnd, uMsg, wParam, lParam&#41;;\r\nend;\r\n\r\nprocedure TEngine.AssignWindowsHandles;\r\nbegin\r\n // Note that for the VCL samples, the device window and focus window\r\n // are not the same.\r\n m_hWnd &#58;= m_hwndRenderWindow;\r\n m_hWndFocus &#58;= m_hwndRenderFullScreen;\r\nend;\r\n\r\n//-----------------------------------------------------------------------------\r\n// Name&#58; CheckForLostFullscreen&#40;&#41;\r\n// Desc&#58; If fullscreen and device was lost &#40;probably due to alt-tab&#41;,\r\n// automatically switch to windowed mode\r\n//-----------------------------------------------------------------------------\r\nfunction TEngine.CheckForLostFullscreen&#58; HResult;\r\nbegin\r\n Result&#58;= S_OK;\r\n if &#40;m_bWindowed&#41; then Exit;\r\n if &#40;FAILED&#40;m_pd3dDevice.TestCooperativeLevel&#41;&#41; then\r\n begin\r\n ForceWindowed;\r\n fAppForm.SetFocus;\r\n Application.BringToFront;\r\n end;\r\nend;\r\n\r\nprocedure TEngine.BuildPresentParamsFromSettings;\r\nbegin\r \n inherited;\r\n m_d3dpp.Flags&#58;= m_d3dpp.Flags or D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;\r\nend;\r\n\r\ nconstructor TMovieEngine.Create;\r\nbegin\r\n inherited;\r\nend;\r\n\r\nDestructor TMovieEngine.Destroy;\r\nbegin\r\n CoUninitialize;\r\n //VideoWindow.put_Visible&#40;FALSE&#41;;\r\n //VideoWindow.put_Owner&#40;0&#41;;\r\n Inherited Destroy;\r\nend;\r\n\r\nProcedure TMovieEngine.AssignEngine&#40;Engine &#58; TEngine&#41;;\r\n\r\nbegin\r\n FEngine &#58;= Engine;\r\n RenderHWD &#58;= FEngine.m_hWnd;\r\n &#40;*if FEngine.m_bWindowed then\r\n RenderHWD &#58;= FEngine.fAppForm.Handle\r\n else\r\n RenderHWD &#58;= FEngine.m_hwndRenderFullScreen;*&#41;\r\nend;\r\n\r\nP rocedure TMovieEngine.Render&#40;Filename &#58; String&#41;;\r\nVar\r\n PWName &#58; array&#91;0..MAX_PATH&#93; of WideChar;\r\n CRect &#58; TRect;\r\nbegin\r\n CoInitialize&#40;nil&#41;;\r\n CoCreateInstance&#40;CLSID_FilterGraph, nil, CLSCTX_INPROC_SERVER,\r\n IID_IGraphBuilder, GraphBuilder&#41;;\r\n &#123; Get the top level interface &#125;\r\n //GraphBuilder &#58;= CreateComObject&#40;CLSID_FilterGraph&#41; as IGraphBuilder;\r\n &#123; Have GraphBuilder do all the grunt work of creating filters and connecting pins &#125;\r\n &#123;$IFNDEF UNICODE&#125;\r\n MultiByteToWideChar&#40;CP_ACP, 0, PChar&#40;FileName&#41;, -1, PWName, MAX_PATH&#41;;\r\n &#123;$ELSE&#125;\r\n lstrcpy&#40;wFileName, strFileName&#41;;\r\n &#123;$ENDIF&#125;\r\n if FAILED&#40;GraphBuilder.RenderFile&#40;PWname,nil&#41;&#41; then\r\n begin\r\n Application.MessageBox&#40; ''A¬§A_A"ASA'A_A'A?íA¬?A¬?A"A¬°A'A?í A¬°ASA'A¬ßA¬ºA.A¬§A'Ac ''+\r\n ''The sample will now exit.'',\r\n ''Movie Render'', MB_ICONERROR or MB_OK &#41;;\r\n end;\r\n &#123; Get a MediaControl interface to display in &#125;\r\n GraphBuilder.QueryInterface&#40;IID_IMediaControl, MediaControl&#41;;\r\n GraphBuilder.QueryInterface&#40;IID_IVideoWindow,Video Window&#41;;\r\n GraphBuilder.QueryInterface&#40;IID_IMediaEventEX,Medi aEvent&#41;;\r\n //MediaEvent.SetNotifyWindow&#40;RenderHWD,WM_GRAPHNOTIF Y,0&#41;;\r\n VideoWindow.put_Owner&#40;RenderHWD&#41;;\r\n VideoWindow.put_WindowStyle&#40;WS_CHILD OR WS_CLIPSIBLINGS &#41;;//OR WS_CLIPCHILDREN&#41;;\r\n //VideoWindow.put_WindowStyleEX&#40;not&#40;WS_EX_CLIENTEDGE or WS_EX_STATICEDGE\r\n // or WS_EX_WINDOWEDGE or WS_EX_DLGMODALFRAME&#41; &#41;;\r\n GetClientRect&#40;RenderHWD,CRect&#41;;\r\n VideoWindow.SetWindowPosition&#40;CRect.Left,CRect.Top ,CRect.Right,CRect.Bottom&#41;;\r\n &#123; Run the MPG once &#125;\r\n MediaControl.Run;\r\nend;\r\n\r\nend.

Clootie
27-01-2005, 08:54 AM
It's rather hard to find out why it's happens from your code. Have you monitored DirectX debug output?

In Destructor TVMR9Graph.Destroy; instead of
if DirectSoundFilter<>nil then
begin
DirectSoundFilter._Release;
DirectSoundFilter:= nil;
end;

you should use simple (for all interfaces):
DirectSoundFilter:= nil;
This is the way you work with interfaces in Delphi.

Attapong
27-01-2005, 10:20 AM
:lol: :lol: :lol: Thanks :D