procedure TForm1.Button1Click(Sender: TObject);
var pGraph: IGraphBuilder;
pMediaControl: IMediaControl;
pEvent: IMediaEvent;
pSeek: IMediaSeeking;
pVidWin: IVideoWindow;
evCode, x, y: Integer;
lpParam1, lpParam2: LONG_PTR;
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(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);
//Wiedergabegröße
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);
pVidWin._Release;
Pointer(pVidWin):=Nil;
pMediaControl._Release;
Pointer(pMediaControl):=Nil;
pEvent._Release;
Pointer(pEvent):=Nil;
pGraph._Release;
Pointer(pGraph):=Nil;
end;