首先将歌曲加入列表,加入一个timer,然后在wmp中打开列表中选择的音乐文件后(即open后,否则会发生错误!),timer每秒检测一次wmp.Position,当wmp.Position=wmp.Length时表示播放完毕,则先将timer禁用(否则会发生错误!)后wmp.close,wmp打开列表中的下一个音乐文件……
附我的测试代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MPlayer, ExtCtrls;
type
TForm1 = class(TForm)
mp: TMediaPlayer;
test: TButton;
stest: TEdit;
od: TOpenDialog;
stest2: TEdit;
tmr: TTimer;
procedure testClick(Sender: TObject);
procedure tmrTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.testClick(Sender: TObject);
begin
tmr.Enabled:=false;
if od.Execute then
mp.FileName:=od.FileName;
mp.Open;
stest.Text:=inttostr(mp.Length);
tmr.Enabled:=true;
end;
procedure TForm1.tmrTimer(Sender: TObject);
begin
stest2.Text:=inttostr(mp.Position);
if mp.Position=mp.Length then
tmr.Enabled:=false;
end;
end.