在你的初始化事件中读到一个listbox中,全局变量Playlist,当然要有个Ttimer控件!它的Enabled属性为false;var i:integer; searchRec:TsearchRec; seat:string; begin try Playlist:=0; filepa:=你的光驱名如(H:\); for i:=0 to 3 do begin if i=0 then seat:='*.mp3'; if i=1 then seat:='*.wav'; if i=2 then seat:='*.mpeg'; if i=3 then seat:='*.mid'; if (FindFirst(filepa+seat, faAnyFile-faDirectory, SearchRec)=0) then begin Form1.ListBox1.Items.Add(filepa+searchrec.Name); while (FindNext(SearchRec) = 0) do Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name)); end; FindClose(SearchRec); end; MediaPlayer1.Filename:=listbox1.items[plsylist]; MediaPlayer1.close; MediaPlayer1.open MediaPlayer1.play; timer1.Enabled:=true; except showmessage('光驱中没有光盘'); end; end; procedure TForm1.Timer1Timer(Sender: TObject); var begin try if MediaPlayer1.Position=MediaPlay.lengthl then begin Playlsit:=Playlist+1; if Playlist<listbox1.items.count then begin MediaPlayer1.Filename:=listbox1.items[plsylist]; MediaPlayer1.close; MediaPlayer1.open MediaPlayer1.play; end else MediaPlayer1.stop; end; except showmessage('请确定光驱中有光盘'); MediaPlayer1.stop; end;end; 好了!随手写的!调式一下吧!
然后就调用相应的方法(如open就播放,pause就暂停,stop就停止)
i:integer;
searchRec:TsearchRec;
seat:string;
begin
try
Playlist:=0;
filepa:=你的光驱名如(H:\);
for i:=0 to 3 do
begin
if i=0 then seat:='*.mp3';
if i=1 then seat:='*.wav';
if i=2 then seat:='*.mpeg';
if i=3 then seat:='*.mid';
if (FindFirst(filepa+seat, faAnyFile-faDirectory, SearchRec)=0) then
begin
Form1.ListBox1.Items.Add(filepa+searchrec.Name);
while (FindNext(SearchRec) = 0) do
Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name));
end;
FindClose(SearchRec);
end;
MediaPlayer1.Filename:=listbox1.items[plsylist];
MediaPlayer1.close;
MediaPlayer1.open
MediaPlayer1.play;
timer1.Enabled:=true;
except
showmessage('光驱中没有光盘');
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
begin
try
if MediaPlayer1.Position=MediaPlay.lengthl then
begin
Playlsit:=Playlist+1;
if Playlist<listbox1.items.count then
begin
MediaPlayer1.Filename:=listbox1.items[plsylist];
MediaPlayer1.close;
MediaPlayer1.open
MediaPlayer1.play;
end
else MediaPlayer1.stop;
end;
except
showmessage('请确定光驱中有光盘');
MediaPlayer1.stop;
end;end;
好了!随手写的!调式一下吧!