Results 1 to 3 of 3

Thread: DelphiX and autorepeat music

  1. #1

    DelphiX and autorepeat music

    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:

    Code:
    MediaPlayer.Notify := True;
    MediaPlayer.OnNotify := NotifyProc;
    fAutorepeat := True;
    and the procedure to repeat:

    Code:
    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?
    Wake up from the dream and live your life to the full

  2. #2

    DelphiX and autorepeat music

    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.

  3. #3

    DelphiX and autorepeat music

    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:

    Code:
    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:

    Code:
    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:
    Wake up from the dream and live your life to the full

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •