问题描述
我有一个名为MediaPlayer1的TMediaPlayer,然后打开一个文件(一首歌曲)并播放它。
现在我的问题是我需要重复播放歌曲,直到程序停止为止。
这个想法是激活表格,然后重复指定的歌曲,直到
MediaPlayer1.Filename:='文件名';
然后将其打开
MediaPlayer1.Open;
然后播放它
MediaPlayer1.Play;
所以现在这首歌正在播放,但是当它结束时我希望它再次播放(重复),然后
我尝试了大卫·赫弗南(David Heffernan)所说的内容,但没有用,我认为我做错了什么,可以请人纠正我。
单位Unit1;
界面
使用
Windows,消息,SysUtils,变体,类,图形,控件,窗体,
对话框,MPlayer,StdCtrls;
type
TForm1 = class(TForm)
MediaPlayer1:TMediaPlayer;
标签1:TLabel;
过程FormActivate(Sender:TObject);
过程MediaPlayer1Notify(Sender:TObject);
私人
{私人声明}
公共
{公开声明}
结尾;
var
Form1:TForm1;
实现
{$ R * .dfm}
过程TForm1.FormActivate(Sender:TObject);
开始
mediaplayer1.FileName:='E:\it project\mario.mid';
mediaplayer1.Open;
mediaplayer1.AutoRewind:= true;
mediaplayer1.Play;
mediaplayer1.Notify:= true;
结尾;
过程TForm1.MediaPlayer1Notify(Sender:TObject);
如果MediaPlayer1.NotifyValue = nvSuccessful则开始
,然后开始
MediaPlayer1.Play;
MediaPlayer1.Notify:= True;
结尾;
结尾;
结尾。
您必须自己组织自动重复。 / p>
为媒体播放器创建 OnNotify
事件。
过程TForm1.MediaPlayer1Notify(Sender:TObject);会在歌曲完成时触发。
如果MediaPlayer1.NotifyValue = nvSuccessful开始
,然后开始
//重新播放歌曲
MediaPlayer1.Play;
MediaPlayer1.Notify:= True; //确保当歌曲结束
时我们得到通知;
结尾;
开始播放歌曲的代码应如下所示:
MediaPlayer1.AutoRewind:= True; //出于明显原因
MediaPlayer1.Play;
MediaPlayer1.Notify:= True; //确保当歌曲结束时我们得到通知
I have a TMediaPlayer called MediaPlayer1 I then open a file(a song) I play it.now my problem is that I need the song to repeat until the program stops.
The idea is that the form activates and then repeats the specified song until the form is closed.
MediaPlayer1.Filename := 'filename';
Then it opens it
MediaPlayer1.Open;
Then it plays it
MediaPlayer1.Play;
So now the song is playing but when it ends I want it to play again(repeat) and then again until the form is closed.
I tried what David Heffernan said but it does not work, I think I did something wrong can someone pleas correct me.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MPlayer, StdCtrls;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure MediaPlayer1Notify(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
begin
mediaplayer1.FileName:='E:\it project\mario.mid';
mediaplayer1.Open;
mediaplayer1.AutoRewind:=true;
mediaplayer1.Play;
mediaplayer1.Notify:=true;
end;
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if MediaPlayer1.NotifyValue=nvSuccessful then begin
MediaPlayer1.Play;
MediaPlayer1.Notify := True;
end;
end;
end.
You have to organise the auto repeat for yourself.
Create an OnNotify
event for the media player. This fires when the song completes.
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if MediaPlayer1.NotifyValue=nvSuccessful then begin
//restart the song
MediaPlayer1.Play;
MediaPlayer1.Notify := True;//ensures we are notified when song completes
end;
end;
The code that starts the song needs to look like this:
MediaPlayer1.AutoRewind := True;//for obvious reasons
MediaPlayer1.Play;
MediaPlayer1.Notify := True;//ensures we are notified when song completes
这篇关于如何重复播放歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!