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

Delphi控件源码

开发平台:

Delphi

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