Unit2.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {========================================================================}
  2. {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
  3. {========================================================================}
  4. {= All Rights Reserved =}
  5. {========================================================================}
  6. {= D 01099 Dresden = Fax.: +49 (0)351-8037944 =}
  7. {= Loewenstr.7a = info@swiftsoft.de =}
  8. {========================================================================}
  9. {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
  10. {========================================================================}
  11. {= This code is for reference purposes only and may not be copied or =}
  12. {= distributed in any format electronic or otherwise except one copy =}
  13. {= for backup purposes. =}
  14. {= =}
  15. {= No Delphi Component Kit or Component individually or in a collection=}
  16. {= subclassed or otherwise from the code in this unit, or associated =}
  17. {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
  18. {= without express permission from SwiftSoft. =}
  19. {= =}
  20. {= For more licence informations please refer to the associated =}
  21. {= HelpFile. =}
  22. {========================================================================}
  23. {= $Date: 05.09.98 - 21:46:18 $ =}
  24. {========================================================================}
  25. unit Unit2;
  26. interface
  27. uses
  28. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  29. Menus, StdCtrls, ExtCtrls, MMObj, MMAVI, MMAVICtl;
  30. type
  31. TAVIPlayer = class(TForm)
  32. AVIControl: TMMAVIControl;
  33. AVIVideoDisplay: TMMAVIVideoDisplay;
  34. Timer: TTimer;
  35. procedure FormCreate(Sender: TObject);
  36. procedure FormShow(Sender: TObject);
  37. procedure FormHide(Sender: TObject);
  38. procedure TimerTimer(Sender: TObject);
  39. private
  40. MinMaxOK: Boolean;
  41. MinWidth,MinHeight,MaxHeight: integer;
  42. procedure WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
  43. procedure SetminMax;
  44. procedure SetInitSize;
  45. public
  46. end;
  47. procedure PlayStream(S: TMMAVIStream);
  48. procedure PlayFile(F: TMMCustomAVIFile);
  49. var
  50. AVIPlayer: TAVIPlayer;
  51. implementation
  52. {$R *.DFM}
  53. {------------------------------------------------------------------------------}
  54. procedure PlayStream(S: TMMAVIStream);
  55. begin
  56. with AVIPlayer.AVIControl do
  57. begin
  58. { first release all previous streams }
  59. FreeStreams;
  60. { now add our stream to the player }
  61. AddStream(S);
  62. if S.StreamType = stAudio then
  63. AVIPlayer.Caption := 'AVI Player - Audio Stream'
  64. else
  65. AVIPlayer.Caption := 'AVI Player - Video Stream';
  66. AVIPlayer.ShowModal;
  67. end;
  68. end;
  69. {------------------------------------------------------------------------------}
  70. procedure PlayFile(F: TMMCustomAVIFile);
  71. begin
  72. with AVIPlayer.AVIControl do
  73. begin
  74. { first release all previous streams }
  75. FreeStreams;
  76. { now add our file (all streams) to the player }
  77. AddFile(F);
  78. if F is TMMAVIFile then
  79. AVIPlayer.Caption := 'AVI Player - '+TMMAVIFile(F).FileName
  80. else
  81. AVIPlayer.Caption := 'AVI Player - Temporary File';
  82. AVIPlayer.ShowModal;
  83. end;
  84. end;
  85. {-- TAVIPlayer ----------------------------------------------------------------}
  86. procedure TAVIPlayer.WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo);
  87. begin
  88. if MinMaxOK then
  89. begin
  90. with Msg.MinMaxInfo^ do
  91. begin
  92. ptMinTrackSize.X := MinWidth; { Minimum width }
  93. ptMinTrackSize.Y := MinHeight; { Minimum height }
  94. ptMaxTrackSize.Y := MaxHeight; { Maximum height }
  95. end;
  96. Msg.Result := 0; { Tell windows you have changed minmaxinfo }
  97. end;
  98. inherited;
  99. end;
  100. {-- TAVIPlayer ----------------------------------------------------------------}
  101. procedure TAVIPlayer.SetMinMax;
  102. begin
  103. MinWidth := (Width-ClientWidth)+AVIControl.MinWidth;
  104. MinHeight:= (Height-ClientHeight)+AVIControl.MinHeight;
  105. MaxHeight := Screen.Height;
  106. if not AVIControl.hasVideo then
  107. begin
  108. Height := MinHeight;
  109. MaxHeight := MinHeight;
  110. end;
  111. end;
  112. {-- TAVIPlayer ----------------------------------------------------------------}
  113. procedure TAVIPlayer.SetInitSize;
  114. var
  115. R: TRect;
  116. begin
  117. if AVIControl.hasVideo then
  118. begin
  119. { get the size of the video }
  120. R := AVIVideoDisplay.GetVideoSize(0);
  121. { now add the Bevel size }
  122. InflateRect(R,AVIVideoDisplay.BevelExtend,AVIVideoDisplay.BevelExtend);
  123. ClientWidth := R.Right-R.Left;
  124. ClientHeight := (R.Bottom-R.Top)+AVIControl.Height;
  125. end
  126. else
  127. begin
  128. ClientWidth := AVIControl.MinWidth;
  129. ClientHeight:= AVIControl.MinHeight;
  130. end;
  131. end;
  132. {-- TAVIPlayer ----------------------------------------------------------------}
  133. procedure TAVIPlayer.FormCreate(Sender: TObject);
  134. begin
  135. MinMaxOK := True;
  136. SetMinMax;
  137. end;
  138. {-- TAVIPlayer ----------------------------------------------------------------}
  139. procedure TAVIPlayer.TimerTimer(Sender: TObject);
  140. begin
  141. Timer.Enabled := False;
  142. AVIControl.Play;
  143. end;
  144. {-- TAVIPlayer ----------------------------------------------------------------}
  145. procedure TAVIPlayer.FormShow(Sender: TObject);
  146. begin
  147. SetMinMax;
  148. SetInitSize;
  149. Timer.Enabled := True;
  150. end;
  151. {-- TAVIPlayer ----------------------------------------------------------------}
  152. procedure TAVIPlayer.FormHide(Sender: TObject);
  153. begin
  154. { stop playing }
  155. AVIControl.Stop;
  156. { free all allocated streams }
  157. AVIControl.FreeStreams;
  158. end;
  159. end.