{打开并播放}
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;
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 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;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
mcisendstring('open c:\123.mid alias mid',nil,0,0);
mcisendstring('play mid notify',nil,0,handle);
end;
procedure TForm1.MMNotify(var Message: TMessage);
Var Buf:Array[0..4095] of Char;
begin
MCISendString('status mid mode',Buf,Sizeof(Buf),0);
if Strpas(Buf)='stopped' then
begin
MciSendString('Seek mid to start',nil,0,0);
MciSendString('Play mid notify',nil,0,handle);
end;
end;
最简单的方法是使用Mediaplayer,好象是在Notify什么事件,
然后根据当将的Mode判断,如果为Stopped则重新播放,如果一定要用API
我临时想的,加一个Timer
在OnTime事件中,(同样使用上面的别名Mid)
Var Buf:Array[0..20] of char;
begin
MciSendString('Status mid mode',buf,20,0);
if strpas(buf)='stopped' then
begin
mcisendstring('seek mid start',nil,0,0);
mcisendstring('play mid',nil,0,0);
end;
end;