如果要实现音乐的回放,可采取下面的方法:
1.循环
var
stop:boolean;
procedure TForm1.ButtonPlayClick(Sender: TObject);
var time:integer;
begin
time:=MediaPlayer1.Length;
stop:=false;
MediaPlayer1.Play;
while not (stop)do
begin
application.ProcessMessages;
if MediaPlayer1.Position=MediaPlayer1.Length
then
MediaPlayer1.Play;
end;
end;
停止:
procedure tform1.buttonStopclick(sender:tobject);
begin
stop:=true;
MediaPlayer1.Stop;
end;
2.利用Timer控件
Timer1.Enabled:=false;
procedure TForm1.ButtonPlayClick(Sender: TObject);
begin
MediaPlayer1.Play;
Timer1.Enabled:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if MediaPlayer1.Position=MediaPlayer1.Length
then
MediaPlayer1.Play;
end;
停止:
procedure tform1.buttonStopclick(sender:tobject);
begin
Timer1.enabled:=false;
MediaPlayer1.stop;
end;
WH(老大?):this time u r not right.
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if ((MediaPlayer1.NotifyValue=nvSuccessful) and
(MediaPlayer1.mode=mpStopped)) then
begin
mediaplayer1.rewind;
mediaplayer1.play;
end;
end;