PDA

View Full Version : DelphiX and autorepeat music



Wizard
18-02-2008, 10:12 AM
Hi everyone. How can I get an MP3 song to repeat once it's finished in my game made with Delphi and unDelphiX?

I have the following in the formCreate:


MediaPlayer.Notify := True;
MediaPlayer.OnNotify := NotifyProc;
fAutorepeat := True;

and the procedure to repeat:


procedure TFormGame.NotifyProc(Sender: TObject);
begin
with Sender as TMediaPlayer do
begin
case Mode of
mpStopped: if fAutoRepeat then
(Sender as tMediaplayer).play;
end;
Notify := True;
end;
end;
The above works perfectly on a normal Delphi app but not with unDelphiX, it stops and doesn't repeat...any ideas?

User137
19-02-2008, 04:12 AM
Diagnose the problem deeper. Print out MediaPlayer.Mode everytime the NotifyProc runs and have a timer show it too somewhere, then you will see where the problem lies.

Wizard
19-02-2008, 09:02 AM
OK :-)

The code in my first post only seems to work when MediaPlayer.Play is called in formActivate, this means that the track will start playing when the form is activated. It does not work in the button's onClick event. This was not what I wanted so I consulted our good friend Google and implimented the following:

Set AutoRewind to true.

Have a global variable - Loop : boolean;

Then in the MediaPlayer.OnNotify the following:


procedure TFormGame.MediaPlayerNotify(Sender: TObject);
begin
if (MediaPlayer.NotifyValue = nvSuccessful) and (Loop=true) then
begin
MediaPlayer.Play;
MediaPlayer.Notify := true;
end;
Then if you have two buttons for stop and play like me:


procedure TFormGame.ColorButtonPlayClick(Sender: TObject);
begin
Loop := true;
MediaPlayer.Play;
MediaPlayer.Notify := true;
end;

procedure TFormGame.ColorButtonStop(Sender: TObject);
begin
Loop := false;
MediaPlayer.Stop;
MediaPlayer.Notify := true;
end;
It works, the track auto repeats once it's finished :-) So it has nothing to do with DelphiX :twisted:

Maybe this will be helpfull to someone else :idea: