1基于DirectShow的媒体播放(可SnapShot)unit Main;
  2基于DirectShow的媒体播放(可SnapShot)
  3基于DirectShow的媒体播放(可SnapShot)interface
  4基于DirectShow的媒体播放(可SnapShot)
  5基于DirectShow的媒体播放(可SnapShot)uses
  6基于DirectShow的媒体播放(可SnapShot)  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7基于DirectShow的媒体播放(可SnapShot)  DirectShow, ExtCtrls, Buttons, ActiveX;
  8基于DirectShow的媒体播放(可SnapShot)
  9基于DirectShow的媒体播放(可SnapShot)const
 10基于DirectShow的媒体播放(可SnapShot)  WM_GraphNotify = WM_App+1;
 11基于DirectShow的媒体播放(可SnapShot)
 12基于DirectShow的媒体播放(可SnapShot)type
 13基于DirectShow的媒体播放(可SnapShot)  TMainForm = class(TForm)
 14基于DirectShow的媒体播放(可SnapShot)    DisplayPanel: TPanel;
 15基于DirectShow的媒体播放(可SnapShot)    SpeedButton1: TSpeedButton;
 16基于DirectShow的媒体播放(可SnapShot)    SpeedButton2: TSpeedButton;
 17基于DirectShow的媒体播放(可SnapShot)    SpeedButton3: TSpeedButton;
 18基于DirectShow的媒体播放(可SnapShot)    SpeedButton4: TSpeedButton;
 19基于DirectShow的媒体播放(可SnapShot)    SpeedButton5: TSpeedButton;
 20基于DirectShow的媒体播放(可SnapShot)    SpeedButton6: TSpeedButton;
 21基于DirectShow的媒体播放(可SnapShot)    SpeedButton7: TSpeedButton;
 22基于DirectShow的媒体播放(可SnapShot)    Image1: TImage;
 23基于DirectShow的媒体播放(可SnapShot)    OpenDialog: TOpenDialog;
 24基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton1Click(Sender: TObject);
 25基于DirectShow的媒体播放(可SnapShot)    procedure FormCreate(Sender: TObject);
 26基于DirectShow的媒体播放(可SnapShot)    procedure FormDestroy(Sender: TObject);
 27基于DirectShow的媒体播放(可SnapShot)    procedure DisplayPanelResize(Sender: TObject);
 28基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton2Click(Sender: TObject);
 29基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton3Click(Sender: TObject);
 30基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton4Click(Sender: TObject);
 31基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton5Click(Sender: TObject);
 32基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton6Click(Sender: TObject);
 33基于DirectShow的媒体播放(可SnapShot)    procedure SpeedButton7Click(Sender: TObject);
 34基于DirectShow的媒体播放(可SnapShot)  private
 35基于DirectShow的媒体播放(可SnapShot)    { Private declarations }
 36基于DirectShow的媒体播放(可SnapShot)  protected
 37基于DirectShow的媒体播放(可SnapShot)    procedure WMGraphNotify(var Msg: TMessage); message WM_GraphNotify;
 38基于DirectShow的媒体播放(可SnapShot)  public
 39基于DirectShow的媒体播放(可SnapShot)    { Public declarations }
 40基于DirectShow的媒体播放(可SnapShot)    GraphBuilder: IGraphBuilder;
 41基于DirectShow的媒体播放(可SnapShot)    VideoWindow: IVideoWindow;
 42基于DirectShow的媒体播放(可SnapShot)    MediaControl: IMediaControl;
 43基于DirectShow的媒体播放(可SnapShot)    MediaEvent: IMediaEventEx;
 44基于DirectShow的媒体播放(可SnapShot)    MediaSeek: IMediaSeeking;
 45基于DirectShow的媒体播放(可SnapShot)    SampleGrabber: ISampleGrabber;
 46基于DirectShow的媒体播放(可SnapShot)
 47基于DirectShow的媒体播放(可SnapShot)    procedure GraphDestory;
 48基于DirectShow的媒体播放(可SnapShot)    procedure OpenFile(const FileName: string);
 49基于DirectShow的媒体播放(可SnapShot)    procedure Play;
 50基于DirectShow的媒体播放(可SnapShot)    procedure Next;
 51基于DirectShow的媒体播放(可SnapShot)    procedure Prev;
 52基于DirectShow的媒体播放(可SnapShot)    procedure Fast;
 53基于DirectShow的媒体播放(可SnapShot)    procedure Slow;
 54基于DirectShow的媒体播放(可SnapShot)    procedure SnapShot;
 55基于DirectShow的媒体播放(可SnapShot)  end;
 56基于DirectShow的媒体播放(可SnapShot)
 57基于DirectShow的媒体播放(可SnapShot)var
 58基于DirectShow的媒体播放(可SnapShot)  MainForm: TMainForm;
 59基于DirectShow的媒体播放(可SnapShot)
 60基于DirectShow的媒体播放(可SnapShot)implementation
 61基于DirectShow的媒体播放(可SnapShot)
 62基于DirectShow的媒体播放(可SnapShot)uses
 63基于DirectShow的媒体播放(可SnapShot)  ComObj;
 64基于DirectShow的媒体播放(可SnapShot)
 65基于DirectShow的媒体播放(可SnapShot){$R *.DFM}
 66基于DirectShow的媒体播放(可SnapShot)
 67基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton1Click(Sender: TObject);
 68基于DirectShow的媒体播放(可SnapShot)begin
 69基于DirectShow的媒体播放(可SnapShot)  if OpenDialog.Execute then
 70基于DirectShow的媒体播放(可SnapShot)  begin
 71基于DirectShow的媒体播放(可SnapShot)    GraphDestory;
 72基于DirectShow的媒体播放(可SnapShot)    OpenFile(OpenDialog.FileName)
 73基于DirectShow的媒体播放(可SnapShot)  end
 74基于DirectShow的媒体播放(可SnapShot)end;
 75基于DirectShow的媒体播放(可SnapShot)
 76基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.FormCreate(Sender: TObject);
 77基于DirectShow的媒体播放(可SnapShot)begin
 78基于DirectShow的媒体播放(可SnapShot)  CoInitialize(nil)
 79基于DirectShow的媒体播放(可SnapShot)end;
 80基于DirectShow的媒体播放(可SnapShot)
 81基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.FormDestroy(Sender: TObject);
 82基于DirectShow的媒体播放(可SnapShot)begin
 83基于DirectShow的媒体播放(可SnapShot)  GraphDestory;
 84基于DirectShow的媒体播放(可SnapShot)
 85基于DirectShow的媒体播放(可SnapShot)  CoUninitialize
 86基于DirectShow的媒体播放(可SnapShot)end;
 87基于DirectShow的媒体播放(可SnapShot)
 88基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.OpenFile(const FileName: string);
 89基于DirectShow的媒体播放(可SnapShot)var
 90基于DirectShow的媒体播放(可SnapShot)  PFileName: array [0..255of WideChar;
 91基于DirectShow的媒体播放(可SnapShot)  Filter: IBaseFilter;
 92基于DirectShow的媒体播放(可SnapShot)  MediaType: TAM_MEDIA_TYPE;
 93基于DirectShow的媒体播放(可SnapShot)  Intf: IInterface;
 94基于DirectShow的媒体播放(可SnapShot)begin
 95基于DirectShow的媒体播放(可SnapShot)  GraphDestory;
 96基于DirectShow的媒体播放(可SnapShot)  
 97基于DirectShow的媒体播放(可SnapShot)  GraphBuilder:=CreateComObject(CLSID_FilterGraph) as IGraphBuilder;
 98基于DirectShow的媒体播放(可SnapShot)
 99基于DirectShow的媒体播放(可SnapShot)  Filter:=CreateComObject(CLSID_SampleGrabber) as IBaseFilter;
100基于DirectShow的媒体播放(可SnapShot)  Filter.QueryInterface(IID_ISampleGrabber, SampleGrabber);
101基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.AddFilter(Filter, 'Grabber');
102基于DirectShow的媒体播放(可SnapShot)  Filter:=nil;
103基于DirectShow的媒体播放(可SnapShot)  ZeroMemory(@MediaType, SizeOf(TAM_MEDIA_TYPE));
104基于DirectShow的媒体播放(可SnapShot)  MediaType.majortype:=MEDIATYPE_Video;
105基于DirectShow的媒体播放(可SnapShot)  MediaType.subtype:=MEDIASUBTYPE_RGB24;
106基于DirectShow的媒体播放(可SnapShot)  MediaType.formattype:=FORMAT_VideoInfo;
107基于DirectShow的媒体播放(可SnapShot)  SampleGrabber.SetMediaType(MediaType);
108基于DirectShow的媒体播放(可SnapShot)  SampleGrabber.SetBufferSamples(True);
109基于DirectShow的媒体播放(可SnapShot)
110基于DirectShow的媒体播放(可SnapShot)  StringToWideChar(FileName, PFileName, 255);
111基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.RenderFile(PFileName, nil);
112基于DirectShow的媒体播放(可SnapShot)
113基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.QueryInterface(IID_IVideoWindow, VideoWindow);
114基于DirectShow的媒体播放(可SnapShot)  VideoWindow.put_Owner(DisplayPanel.Handle);
115基于DirectShow的媒体播放(可SnapShot)  VideoWindow.put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS);
116基于DirectShow的媒体播放(可SnapShot)  VideoWindow.put_Visible(True);
117基于DirectShow的媒体播放(可SnapShot)  DisplayPanelResize(nil);
118基于DirectShow的媒体播放(可SnapShot)
119基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.QueryInterface(IID_IMediaSeeking, MediaSeek);
120基于DirectShow的媒体播放(可SnapShot)  MediaSeek.SetTimeFormat(Time_Format_Frame);
121基于DirectShow的媒体播放(可SnapShot)
122基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.QueryInterface(IID_IMediaControl, MediaControl);
123基于DirectShow的媒体播放(可SnapShot)
124基于DirectShow的媒体播放(可SnapShot)  GraphBuilder.QueryInterface(IID_IMediaEventEx, MediaEvent);
125基于DirectShow的媒体播放(可SnapShot)  MediaEvent.SetNotifyWindow(Handle, WM_GraphNotify, 0);
126基于DirectShow的媒体播放(可SnapShot)end;
127基于DirectShow的媒体播放(可SnapShot)
128基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.GraphDestory;
129基于DirectShow的媒体播放(可SnapShot)begin
130基于DirectShow的媒体播放(可SnapShot)  if VideoWindow<>nil then
131基于DirectShow的媒体播放(可SnapShot)  begin
132基于DirectShow的媒体播放(可SnapShot)    VideoWindow.put_Visible(False);
133基于DirectShow的媒体播放(可SnapShot)    VideoWindow.put_Owner(0)
134基于DirectShow的媒体播放(可SnapShot)  end;
135基于DirectShow的媒体播放(可SnapShot)  VideoWindow:=nil;
136基于DirectShow的媒体播放(可SnapShot)
137基于DirectShow的媒体播放(可SnapShot)  MediaControl:=nil;
138基于DirectShow的媒体播放(可SnapShot)
139基于DirectShow的媒体播放(可SnapShot)  MediaEvent:=nil;
140基于DirectShow的媒体播放(可SnapShot)
141基于DirectShow的媒体播放(可SnapShot)  GraphBuilder:=nil
142基于DirectShow的媒体播放(可SnapShot)end;
143基于DirectShow的媒体播放(可SnapShot)
144基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.DisplayPanelResize(Sender: TObject);
145基于DirectShow的媒体播放(可SnapShot)begin
146基于DirectShow的媒体播放(可SnapShot)  if VideoWindow<>nil then
147基于DirectShow的媒体播放(可SnapShot)    VideoWindow.SetWindowPosition(00, DisplayPanel.Width, DisplayPanel.Height)
148基于DirectShow的媒体播放(可SnapShot)end;
149基于DirectShow的媒体播放(可SnapShot)
150基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton2Click(Sender: TObject);
151基于DirectShow的媒体播放(可SnapShot)begin
152基于DirectShow的媒体播放(可SnapShot)  Play
153基于DirectShow的媒体播放(可SnapShot)end;
154基于DirectShow的媒体播放(可SnapShot)
155基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.WMGraphNotify(var Msg: TMessage);
156基于DirectShow的媒体播放(可SnapShot)var
157基于DirectShow的媒体播放(可SnapShot)  EventCode: Integer;
158基于DirectShow的媒体播放(可SnapShot)  Param1, Param2: Integer;
159基于DirectShow的媒体播放(可SnapShot)  CurrentPosition, EndPosition: Int64;
160基于DirectShow的媒体播放(可SnapShot)begin
161基于DirectShow的媒体播放(可SnapShot)  if MediaEvent<>nil then
162基于DirectShow的媒体播放(可SnapShot)  begin
163基于DirectShow的媒体播放(可SnapShot)    while MediaEvent.GetEvent(EventCode, Param1, Param2, 0)=S_OK do
164基于DirectShow的媒体播放(可SnapShot)    begin
165基于DirectShow的媒体播放(可SnapShot)      MediaEvent.FreeEventParams(EventCode, Param1, Param2);
166基于DirectShow的媒体播放(可SnapShot)      if EventCode=EC_Complete then
167基于DirectShow的媒体播放(可SnapShot)      begin
168基于DirectShow的媒体播放(可SnapShot)        if MediaControl<>nil then
169基于DirectShow的媒体播放(可SnapShot)          MediaControl.Stop;
170基于DirectShow的媒体播放(可SnapShot)        if MediaSeek<>nil then
171基于DirectShow的媒体播放(可SnapShot)        begin
172基于DirectShow的媒体播放(可SnapShot)          CurrentPosition:=0;
173基于DirectShow的媒体播放(可SnapShot)          MediaSeek.SetPositions(CurrentPosition,
174基于DirectShow的媒体播放(可SnapShot)            AM_SEEKING_AbsolutePositioning,
175基于DirectShow的媒体播放(可SnapShot)            EndPosition, AM_SEEKING_NoPositioning)
176基于DirectShow的媒体播放(可SnapShot)        end
177基于DirectShow的媒体播放(可SnapShot)      end
178基于DirectShow的媒体播放(可SnapShot)    end
179基于DirectShow的媒体播放(可SnapShot)  end
180基于DirectShow的媒体播放(可SnapShot)end;
181基于DirectShow的媒体播放(可SnapShot)
182基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton3Click(Sender: TObject);
183基于DirectShow的媒体播放(可SnapShot)begin
184基于DirectShow的媒体播放(可SnapShot)  Next
185基于DirectShow的媒体播放(可SnapShot)end;
186基于DirectShow的媒体播放(可SnapShot)
187基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton4Click(Sender: TObject);
188基于DirectShow的媒体播放(可SnapShot)begin
189基于DirectShow的媒体播放(可SnapShot)  Prev
190基于DirectShow的媒体播放(可SnapShot)end;
191基于DirectShow的媒体播放(可SnapShot)
192基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton5Click(Sender: TObject);
193基于DirectShow的媒体播放(可SnapShot)begin
194基于DirectShow的媒体播放(可SnapShot)  Fast
195基于DirectShow的媒体播放(可SnapShot)end;
196基于DirectShow的媒体播放(可SnapShot)
197基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton6Click(Sender: TObject);
198基于DirectShow的媒体播放(可SnapShot)begin
199基于DirectShow的媒体播放(可SnapShot)  Slow
200基于DirectShow的媒体播放(可SnapShot)end;
201基于DirectShow的媒体播放(可SnapShot)
202基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SpeedButton7Click(Sender: TObject);
203基于DirectShow的媒体播放(可SnapShot)begin
204基于DirectShow的媒体播放(可SnapShot)  SnapShot
205基于DirectShow的媒体播放(可SnapShot)end;
206基于DirectShow的媒体播放(可SnapShot)
207基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.Play;
208基于DirectShow的媒体播放(可SnapShot)begin
209基于DirectShow的媒体播放(可SnapShot)  if MediaControl<>nil then
210基于DirectShow的媒体播放(可SnapShot)    MediaControl.Run
211基于DirectShow的媒体播放(可SnapShot)end;
212基于DirectShow的媒体播放(可SnapShot)
213基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.Next;
214基于DirectShow的媒体播放(可SnapShot)var
215基于DirectShow的媒体播放(可SnapShot)  CurrentPosition, EndPosition: Int64;
216基于DirectShow的媒体播放(可SnapShot)begin
217基于DirectShow的媒体播放(可SnapShot)  if MediaControl<>nil then
218基于DirectShow的媒体播放(可SnapShot)    MediaControl.Pause;
219基于DirectShow的媒体播放(可SnapShot)  if MediaSeek<>nil then
220基于DirectShow的媒体播放(可SnapShot)  begin
221基于DirectShow的媒体播放(可SnapShot)    MediaSeek.GetPositions(CurrentPosition, EndPosition);
222基于DirectShow的媒体播放(可SnapShot)    Inc(CurrentPosition);
223基于DirectShow的媒体播放(可SnapShot)    MediaSeek.SetPositions(CurrentPosition, AM_SEEKING_AbsolutePositioning,
224基于DirectShow的媒体播放(可SnapShot)      EndPosition, AM_SEEKING_NoPositioning)
225基于DirectShow的媒体播放(可SnapShot)  end
226基于DirectShow的媒体播放(可SnapShot)end;
227基于DirectShow的媒体播放(可SnapShot)
228基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.Prev;
229基于DirectShow的媒体播放(可SnapShot)var
230基于DirectShow的媒体播放(可SnapShot)  CurrentPosition, EndPosition: Int64;
231基于DirectShow的媒体播放(可SnapShot)begin
232基于DirectShow的媒体播放(可SnapShot)  if MediaControl<>nil then
233基于DirectShow的媒体播放(可SnapShot)    MediaControl.Pause;
234基于DirectShow的媒体播放(可SnapShot)  if MediaSeek<>nil then
235基于DirectShow的媒体播放(可SnapShot)  begin
236基于DirectShow的媒体播放(可SnapShot)    MediaSeek.GetPositions(CurrentPosition, EndPosition);
237基于DirectShow的媒体播放(可SnapShot)    Dec(CurrentPosition);
238基于DirectShow的媒体播放(可SnapShot)    MediaSeek.SetPositions(CurrentPosition, AM_SEEKING_AbsolutePositioning,
239基于DirectShow的媒体播放(可SnapShot)      EndPosition, AM_SEEKING_NoPositioning)
240基于DirectShow的媒体播放(可SnapShot)  end
241基于DirectShow的媒体播放(可SnapShot)end;
242基于DirectShow的媒体播放(可SnapShot)
243基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.Fast;
244基于DirectShow的媒体播放(可SnapShot)begin
245基于DirectShow的媒体播放(可SnapShot)  if MediaSeek<>nil then
246基于DirectShow的媒体播放(可SnapShot)    MediaSeek.SetRate(2)
247基于DirectShow的媒体播放(可SnapShot)end;
248基于DirectShow的媒体播放(可SnapShot)
249基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.Slow;
250基于DirectShow的媒体播放(可SnapShot)begin
251基于DirectShow的媒体播放(可SnapShot)  if MediaSeek<>nil then
252基于DirectShow的媒体播放(可SnapShot)    MediaSeek.SetRate(0.125)
253基于DirectShow的媒体播放(可SnapShot)end;
254基于DirectShow的媒体播放(可SnapShot)
255基于DirectShow的媒体播放(可SnapShot)procedure TMainForm.SnapShot;
256基于DirectShow的媒体播放(可SnapShot)var
257基于DirectShow的媒体播放(可SnapShot)  MediaType: TAM_MEDIA_TYPE;
258基于DirectShow的媒体播放(可SnapShot)  VideoInfoHeader: TVideoInfoHeader;
259基于DirectShow的媒体播放(可SnapShot)  BitmapInfo: TBitmapInfo;
260基于DirectShow的媒体播放(可SnapShot)  Bitmap: HBitmap;
261基于DirectShow的媒体播放(可SnapShot)  Buffer: Pointer;
262基于DirectShow的媒体播放(可SnapShot)  BufferSize: Integer;
263基于DirectShow的媒体播放(可SnapShot)begin
264基于DirectShow的媒体播放(可SnapShot)  SampleGrabber.GetConnectedMediaType(MediaType);
265基于DirectShow的媒体播放(可SnapShot)
266基于DirectShow的媒体播放(可SnapShot)  ZeroMemory(@VideoInfoHeader, SizeOf(TVideoInfoHeader));
267基于DirectShow的媒体播放(可SnapShot)  CopyMemory(@VideoInfoHeader, MediaType.pbFormat, SizeOf(VideoInfoHeader));
268基于DirectShow的媒体播放(可SnapShot)
269基于DirectShow的媒体播放(可SnapShot)  ZeroMemory(@BitmapInfo, SizeOf(TBitmapInfo));
270基于DirectShow的媒体播放(可SnapShot)  CopyMemory(@BitmapInfo, @VideoInfoHeader.bmiHeader, SizeOf(VideoInfoHeader.bmiHeader));
271基于DirectShow的媒体播放(可SnapShot)
272基于DirectShow的媒体播放(可SnapShot)  Bitmap:=CreateDIBSection(0, BitmapInfo, DIB_RGB_COLORS, Buffer, 00);
273基于DirectShow的媒体播放(可SnapShot)  SampleGrabber.GetCurrentBuffer(BufferSize, Buffer);
274基于DirectShow的媒体播放(可SnapShot)
275基于DirectShow的媒体播放(可SnapShot)  Image1.Picture.Bitmap.Handle:=Bitmap
276基于DirectShow的媒体播放(可SnapShot)end;
277基于DirectShow的媒体播放(可SnapShot)
278基于DirectShow的媒体播放(可SnapShot)end
279基于DirectShow的媒体播放(可SnapShot)

 

相关文章: