播放AVI动画源代码如下:
unit media1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, MPlayer;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Timer1: TTimer;
TrackBar1: TTrackBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
OpenDialog1: TOpenDialog;
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button3Click(Sender: TObject);
begin
if mediaplayer1.filename<>'' then
begin
mediaplayer1.Close;
timer1.enabled:=false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.execute then
begin
mediaplayer1.filename:=opendialog1.filename;
timer1.enabled:=false;
mediaplayer1.close;
mediaplayer1.Open;
mediaplayer1.timeformat:=tfhms;
caption:=opendialog1.filename;
trackbar1.min:=0;
trackbar1.max:=mediaplayer1.length;
trackbar1.position:=0;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if mediaplayer1.filename<>'' then
begin
mediaplayer1.wait:=false;
mediaplayer1.play;
timer1.enabled:=true;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
trackbar1.position:=mediaplayer1.position;
end;
end.