How to get music to play in Delphi 7?

大兔子大兔子 提交于 2019-12-05 17:30:52

Use the TMediaPlayer component, it's on the System tab of the component palette.

procedure TForm1.FormActivate(Sender: TObject);
begin
  MediaPlayer1.FileName := '<fill in>.mp3';
  MediaPlayer1.Open;
  MediaPlayer1.Play;
end;

Set the Visible property to False.


Edit in response to OP's comment:

To repeat the song, you can use the TTimer component, also found on the System tab. To repeat the song with a one second delay:

procedure TForm1.FormActivate(Sender: TObject);
begin
  MediaPlayer1.FileName := '<fill in>.mp3';
  MediaPlayer1.Open;
  MediaPlayer1.TimeFormat := tfMilliseconds;
  Timer1.Interval := MediaPlayer1.Length + 1000;
  MediaPlayer1.Play;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  MediaPlayer1.Play;
end;

Set the timer's Enabled property to False.

You can use TMediaPlayerComponent.
Here you can find a tutorial on how to use it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!