main.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit main;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  5.   Dialogs, Menus, DSPack, StdCtrls, ComCtrls, dsutil, Buttons, ToolWin,
  6.   ImgList, SelectURL;
  7. type
  8.   TFormPlayWin = class(TForm)
  9.     FilterGraph: TFilterGraph;
  10.     VideoWindow: TVideoWindow;
  11.     MainMenu: TMainMenu;
  12.     OpenDialog: TOpenDialog;
  13.     FileMenu: TMenuItem;
  14.     OpenMenu: TMenuItem;
  15.     OpenURLMenu: TMenuItem;
  16.     ExitMenu: TMenuItem;
  17.     TrackBar: TDSTrackBar;
  18.     ImageList: TImageList;
  19.     StatusBar: TStatusBar;
  20.     ToolBar: TToolBar;
  21.     btPlay: TToolButton;
  22.     btPause: TToolButton;
  23.     btStop: TToolButton;
  24.     ToolButton1: TToolButton;
  25.     SoundLevel: TTrackBar;
  26.     btFullScreen: TToolButton;
  27.     PopupMenu: TPopupMenu;
  28.     Play1: TMenuItem;
  29.     Pause1: TMenuItem;
  30.     Stop1: TMenuItem;
  31.     FullScreen1: TMenuItem;
  32.     log: TMemo;
  33.     ToolButton2: TToolButton;
  34.     procedure OpenMenuClick(Sender: TObject);
  35.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  36.     procedure btPlayClick(Sender: TObject);
  37.     procedure btPauseClick(Sender: TObject);
  38.     procedure btStopClick(Sender: TObject);
  39.     procedure TrackBarTimer(sender: TObject; CurrentPos,
  40.       StopPos: Cardinal);
  41.     procedure SoundLevelChange(Sender: TObject);
  42.     procedure ExitMenuClick(Sender: TObject);
  43.     procedure OpenURLMenuClick(Sender: TObject);
  44.     procedure btFullScreenClick(Sender: TObject);
  45.     procedure FilterGraphDSEvent(sender: TComponent; Event, Param1,
  46.       Param2: Integer);
  47.   private
  48.     { D閏larations priv閑s }
  49.   public
  50.     { D閏larations publiques }
  51.   end;
  52. var
  53.   FormPlayWin: TFormPlayWin;
  54. implementation
  55. uses DirectShow9;
  56. {$R *.dfm}
  57. procedure TFormPlayWin.OpenMenuClick(Sender: TObject);
  58. begin
  59.   if OpenDialog.Execute then
  60.   begin
  61.     if not FilterGraph.Active then FilterGraph.Active := true;
  62.     FilterGraph.ClearGraph;
  63.     FilterGraph.RenderFile(OpenDialog.FileName);
  64.     VideoWindow.PopupMenu := PopupMenu;
  65.     SoundLevel.Position := FilterGraph.Volume;
  66.     FilterGraph.Play;
  67.   end;
  68. end;
  69. procedure TFormPlayWin.FormCloseQuery(Sender: TObject;
  70.   var CanClose: Boolean);
  71. begin
  72.   // Important
  73.   FilterGraph.ClearGraph;
  74. end;
  75. procedure TFormPlayWin.btPlayClick(Sender: TObject);
  76. begin
  77.   if not FilterGraph.Active then OpenMenuClick(nil)
  78.                             else FilterGraph.play;
  79. end;
  80. procedure TFormPlayWin.btPauseClick(Sender: TObject);
  81. begin
  82.   FilterGraph.Pause;
  83. end;
  84. procedure TFormPlayWin.btStopClick(Sender: TObject);
  85. begin
  86.   FilterGraph.Stop;
  87. end;
  88. procedure TFormPlayWin.TrackBarTimer(sender: TObject; CurrentPos,
  89.   StopPos: Cardinal);
  90. begin
  91.   StatusBar.SimpleText := format('Position: %s Duration: %s',
  92.     [TimeToStr(CurrentPos / MiliSecPerDay), TimeToStr(StopPos / MiliSecPerDay)])
  93. end;
  94. procedure TFormPlayWin.SoundLevelChange(Sender: TObject);
  95. begin
  96.   FilterGraph.Volume := SoundLevel.Position;
  97. end;
  98. procedure TFormPlayWin.ExitMenuClick(Sender: TObject);
  99. begin
  100.   FormPlayWin.Close;
  101. end;
  102. procedure TFormPlayWin.OpenURLMenuClick(Sender: TObject);
  103. begin
  104.   FormSelectURL:= TFormSelectURL.Create(nil);
  105.   if FormSelectURL.ShowModal = mrOK then
  106.   begin
  107.     if not FilterGraph.Active then FilterGraph.Active := true;
  108.     FilterGraph.ClearGraph;
  109.     FilterGraph.RenderFile(FormSelectURL.URL.Text);
  110.     VideoWindow.PopupMenu := PopupMenu;
  111.     SoundLevel.Position := FilterGraph.Volume;
  112.     FilterGraph.Play;
  113.   end;
  114.   FormSelectURL.Free;
  115. end;
  116. procedure TFormPlayWin.btFullScreenClick(Sender: TObject);
  117. begin
  118.   VideoWindow.FullScreen := not VideoWindow.FullScreen;
  119.   btFullScreen.Down := VideoWindow.FullScreen;
  120. end;
  121. procedure TFormPlayWin.FilterGraphDSEvent(sender: TComponent; Event,
  122.   Param1, Param2: Integer);
  123. begin
  124.   log.Lines.Add(GetEventCodeDef(event))
  125. end;
  126. end.