var m_pVideo: IGraphBuilder;
MediaSeeking: IMediaSeeking;
MediaPosition: IMediaPosition;
Duration,CurrentPos : int64;
VideoWindow:IVideoWindow;
pControl : IMediaControl;
//用户命令接口,用来控制过滤器容器
pEvent : IMediaEvent;
//过滤器容器事件接口
hr : HRESULT;
Tmp,hour,min,Second : integer;
_wfile: array[0..MAX_PATH - 1] of wchar;
begin
CoCreateInstance(CLSID_FilterGraph, nil, CLSCTX_INPROC, IID_IGraphBuilder, m_pVideo);
m_pVideo.QueryInterface(IMediaControl, pControl);
m_pVideo.QueryInterface(IMediaEvent, pEvent);
m_pVideo.QueryInterface(IID_IMediaPosition, MediaPosition);
m_pVideo.QueryInterface(IID_IMediaSeeking, MediaSeeking);
MultiByteToWideChar(CP_ACP, 0, pChar(Opendialog1.FileName), -1, @_wfile, MAX_PATH);
hr := m_pVideo.RenderFile(_wfile,nil);
MediaSeeking.GetDuration(Duration);//得到总时间
Tmp := Trunc(Duration / 10000000);
min := Trunc(Tmp / 60) - hour * 60;;
min := Trunc(Tmp / 60);
Second := Trunc(Tmp mod 60);
TrackBar1.Max := Tmp;
//second
label1.Caption := Format('%.2d:%.2d:%.2d',[hour,min,Second]);
if HRESULT(hr) >= 0 then
begin
hr := pControl.Run();
Playing := true;
Button4.Enabled := true;
Button5.Enabled := true;
IsOver := false;
IsOpenFile := true;
Timer1.Enabled := true;
if HRESULT(hr) >= 0 then
begin
(m_pVideo as Ivideowindow).put_Owner(Panel1.handle);
(m_pVideo as IMediaPosition).get_StopTime(t);
(m_pVideo as IVideowindow).put_WindowStyle(GetWindowLong(Panel1.handle,GWL_STYLE) OR WS_CHILD OR WS_CLIPSIBLINGS);
(m_pVideo as IVideowindow).put_WindowStyle(GetWindowLong(Panel1.handle,GWL_STYLE));
(m_pVideo as IVideoWindow).SetWindowPosition(0,0,Panel1.width,Panel1.height);
end;
end;
end;