uses ..., DirectShow9;
procedure TForm1.Button1Click(Sender: TObject);
var pGraph: IGraphBuilder;
pMediaControl: IMediaControl;
pEvent: IMediaEvent;
pSeek: IMediaSeeking;
pVidWin: IVideoWindow;
evCode, x, y, lpParam1, lpParam2: Integer;
tim, dim: Int64;
begin
if Not OpenDialog1.Execute
then exit;
CoCreateInstance(CLSID_FilterGraph,
Nil, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, pGraph);
pGraph.QueryInterface(IID_IMediaControl, pMediaControl);
pGraph.QueryInterface(IID_IMediaEventEx, pEvent);
pGraph.RenderFile(PWideChar(WideString(OpenDialog1.FileName)),
Nil);
pGraph.QueryInterface(IID_IMediaSeeking, pSeek);
pSeek.GetDuration(tim);
Label1.Caption:=IntToStr(tim
div 10000000);
pGraph.QueryInterface(IID_IVideoWindow, pVidWin);
pVidWin.put_Owner(
Handle);
pVidWin.put_WindowStyle(WS_CHILD);
pVidWin.get_Width(x);
pVidWin.get_Height(y);
pVidWin.SetWindowPosition(2, Panel1.Height+2, x, y);
weiter:=true;
pMediaControl.Run;
while weiter
do
begin
if pEvent.GetEvent(evCode, lpParam1, lpParam2, 0)<>E_ABORT
then
begin
if evCode=EC_COMPLETE
then weiter:=false;
pEvent.FreeEventParams(evCode, lpParam1, lpParam2);
end;
pSeek.GetPositions(tim, dim);
Label2.Caption:=IntToStr(tim
div 10000000);
Application.ProcessMessages;
end;
pVidWin.put_Visible(FALSE);
pVidWin.put_Owner(0);
end;