一个简单的复读程序
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, RealAudioObjects_TLB, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Bevel1: TBevel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
OpenDialog1: TOpenDialog;
Label1: TLabel;
Label3: TLabel;
Label5: TLabel;
Label2: TLabel;
Label4: TLabel;
Bevel2: TBevel;
RealAudio1: TRealAudio;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure RealAudio1PresentationClosed(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure RealAudio1PositionChange(Sender: TObject;
lPos,
lLen: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
start_pos,fu:integer;
loop:boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if form1.OpenDialog1.Execute then
begin
form1.RealAudio1.SetSource(form1.OpenDialog1.FileName);
label4.Caption:= form1.OpenDialog1.FileName;
if RealAudio1.CanPlay then
{当能够播放时再进行播放功能设置}
begin
loop:=true;
RealAudio1.DoPlay {执行REAL控件的播放操作}
Button2.Enabled :=false;{设置播放按钮不可用}
Button3.Enabled :=true;{设置暂停按钮为可用}
Button4.Enabled :=true;{设置停止按钮为可用}
button4.SetFocus;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if RealAudio1.CanPlay then
{当能够播放时再进行播放功能设置}
begin
loop:=true;
RealAudio1.DoPlay {执行REAL控件的播放操作}
Button2.Enabled :=false;{设置播放按钮不可用}
Button3.Enabled :=true;{设置暂停按钮为可用}
Button4.Enabled :=true;{设置停止按钮为可用}
button4.SetFocus;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if RealAudio1.CanPlayPause then
{当可以进行暂停设置时再进行操作}
begin
RealAudio1.DoPlayPause {执行REAL控件的暂停功能}
Button3.Enabled :=false;{设置暂停按钮不可用}
Button2.Enabled :=true;{设置播放铵钮为可用}
button1.SetFocus;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if RealAudio1.CanStop then
{当能够进行停止操作时再进行程序设置}
begin
loop:=false;
RealAudio1.DoStop {执行REAL控件的停止功能}
Button4.Enabled :=false;{设置停止按钮为不可用}
Button3.Enabled :=false;{设置暂停按钮为不可用}
Button2.Enabled :=true;{设置播放按钮为可用}
button2.SetFocus;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
RealAudio1.FreeOnRelease
application.Terminate;
end;
procedure TForm1.RealAudio1PresentationClosed(Sender: TObject);
begin
Button2.Enabled :=true;{设置播放按钮为可用}
if loop then
button2.Click;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
loop:=true;
fu:=1;
label1.Caption:='';
label4.Caption:='';
label5.Caption:='0';
end;
procedure TForm1.Button1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if button2.Enabled=false then
if key= VK_CONTROL then
begin
if fu=1 then
//第一次按ctrl
begin
start_pos:= RealAudio1.GetPosition;
label1.Caption:=inttostr(start_pos);
fu:= 2;
end
else
begin
RealAudio1.SetPosition(start_pos);
button2.Click;
end;
end;
if key= VK_SHIFT then
begin
fu:=1;
RealAudio1.SetPosition(RealAudio1.GetPosition);
label1.Caption:= '';
end;
end;
procedure TForm1.RealAudio1PositionChange(Sender: TObject;
lPos,
lLen: Integer);
begin
label5.Caption:=inttostr(RealAudio1.GetPosition);
end;
end.