procedure TForm1.Button1Click(Sender: TObject);
begin
SendMciStr('Open C:\123.mid alias mid');
SendMciStr('Play mid notify');
end;
procedure TForm1.MCINotify(var Message: TMessage);
begin
if SendMciStr('Status mid mode')='stopped' then
begin
SendMciStr('Seek mid to start');
SendMciStr('Play mid notify');
end;
end;
function TForm1.SendMCIStr(const Value: String):PChar;
Var Buf:Array[0..4095] of char;
begin
MCISendString(PChar(Value),Buf,Sizeof(Buf),Handle);
Result:=Buf;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMCiStr('Pause mid notify');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SendMCiStr('Play mid notify');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SendMciStr('Close mid');
end;
end.
回复人:yeah(2000-8-22 1:39:00) 得0分
下面的程序我已实际编译运行过,随便你暂停多少次,都可以再次循环播放,
其中Button1为打开并播放,Button2为暂停,Button3恢复,Button4关闭。
unit Unit1;
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMciStr('Open C:\123.mid alias mid');
SendMciStr('Play mid notify');
end;
procedure TForm1.MCINotify(var Message: TMessage);
begin
if SendMciStr('Status mid mode')='stopped' then
begin
SendMciStr('Seek mid to start');
SendMciStr('Play mid notify');
end;
end;
function TForm1.SendMCIStr(const Value: String):PChar;
Var Buf:Array[0..4095] of char;
begin
MCISendString(PChar(Value),Buf,Sizeof(Buf),Handle);
Result:=Buf;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMCiStr('Pause mid notify');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SendMCiStr('Play mid notify');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SendMciStr('Close mid');
end;
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
protected
procedure MCINOTIFY(Var Message:TMessage); message MM_MCINOTIFY;
private
nowloop:boolean;
function SendMCIStr(Const Msg:String):PChar;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{打开并播放}
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMciStr('open c:\123.mid alias mid');
Sendmcistr('play mid notify');
Nowloop:=true;
end;
{Callback}
procedure TForm1.MCINOTIFY(var Message: TMessage);
begin
if nowloop and (SendmciStr('Status mid mode')='stopped') then
begin
sendmcistr('seek mid to start');
sendmcistr('play mid notify');
end;
end;
{暂停(实际上是停止,但效果一样)}
procedure TForm1.Button2Click(Sender: TObject);
begin
nowloop:=False;
mcisendstring('stop mid',nil,0,0);
end;
{关闭}
procedure TForm1.Button4Click(Sender: TObject);
begin
sendmcistr('close mid');
end;
{公用函数}
function TForm1.SendMCIStr(const Msg: String): PChar;
Var Buf:Array[0..4095] of Char;
begin
MciSendString(PChar(msg),Buf,sizeof(buf),Handle);
Result:=Buf;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
button4click(nil);
end;