问题描述
在我的程序的OnFormActivate事件中,我需要让音乐在程序开始时在后台播放。我有要使用的歌曲,但我不知道Delphi需要使用什么命令才能开始播放该歌曲。
感谢您的帮助:)
使用TMediaPlayer
过程TForm1.FormActivate(Sender:TObject);组件,位于组件面板的系统选项卡上。
开始
MediaPlayer1.FileName:=‘< fill> .mp3’;
MediaPlayer1.Open;
MediaPlayer1.Play;
结尾;
将 Visible
属性设置为False。 / p>
编辑,以回应OP的评论:
要重复播放歌曲,可以使用系统选项卡上的TTimer组件。要延迟一秒钟重复播放歌曲:
过程TForm1.FormActivate(Sender:TObject);
开始
MediaPlayer1.FileName:=‘< fill> .mp3’;
MediaPlayer1.Open;
MediaPlayer1.TimeFormat:= tf毫秒
Timer1.Interval:= MediaPlayer1.Length + 1000;
MediaPlayer1.Play;
Timer1.Enabled:=真;
结尾;
过程TForm1.Timer1Timer(Sender:TObject);
开始
MediaPlayer1.Play;
结尾;
将计时器的 Enabled
属性设置为False。
I need to get music to play in the background in the start of the program in the OnFormActivate event for my program. I have the song I want to use but I dont know what command Delphi needs to use in order to start playing that song.
Thanks for you help guys :)
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.
这篇关于如何在Delphi 7中播放音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!