PDA

View Full Version : MediaPlayer auto-repeat mp3



Wizard
08-04-2009, 09:09 AM
Auto-repeat music using Delphi’s TMediaPlayer

Do you have a nice mp3 music track playing in your game designed with Pascal? Do you need the mp3 track to auto-repeat once it’s finished? The following code will do just that, just make sure AutoOpen, AutoRewind & AutoEnable is set to True in the object inspector of the Media Player:



var
Form1: TForm1;
Loop : boolean;

implementation

{$R *.dfm}

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if (MediaPlayer1.NotifyValue = nvSuccessful) and (Loop=true) then
begin
MediaPlayer1.Play;
MediaPlayer1.Notify := true;
end;
end;

procedure TForm1.PlayClick(Sender: TObject);
begin
Loop := true;
MediaPlayer1.Play;
MediaPlayer1.Notify := true;
end;

procedure TForm1.StopClick(Sender: TObject);
begin
Loop := false;
MediaPlayer1.Stop;
MediaPlayer1.Notify := true;
end;
end.

Cer3brus
14-04-2009, 08:14 AM
Thanks!!
This'll come in handy :)