сейчас я тоже пишу плеер вот таким кодом я пользуюсь:
Код:
//формируем список файлов
procedure TForm1.PlayList(Path:String);
var
SearchRec: TSearchRec;
Ext: string;
begin
ListBox1.Clear;
if FindFirst(Path + '*.*', faAnyFile, SearchRec) = 0 then
repeat
Ext := LowerCase(ExtractFileExt(SearchRec.Name));
if (Ext = '.mp3') or (Ext = '.wav') or (Ext = '.avi') or (Ext = '.ogg') or (Ext = '.wav') or (Ext = '.mpg') or (Ext = '.mac') or (Ext = '.flac') or (Ext = '.wv') or (Ext = '.wm') or (Ext = '.tta') or (Ext = '.ofr') or (Ext = '.tak') or (Ext = '.mpc') or (Ext = '.wma') then
ListBox1.Items.Add(SearchRec.Name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
//воспроизвести композицию, название котрой выделено в списке
procedure TForm1.Play;
begin
Label1.Caption := ListBox1.Items[ListBox1.ItemIndex];
MediaPlayer1.FileName := cDir + '\' + ListBox1.Items[ListBox1.ItemIndex];
try
MediaPlayer1.Open;
except
on EMCIDeviceError do
begin
ShowMessage('Ошибка обращения к файлу');
Exit;
end;
end;
MediaPlayer1.Play;
min := 0;
sec := 0;
Timer1.Enabled := True;
SpeedButton1.Caption := 'Стоп';
Label3.Caption := ListBox1.Items[ListBox1.ItemIndex];
MediaPlayer1.FileName := cDir + '\' + ListBox1.Items[ListBox1.ItemIndex];
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ GetDir(0,cDir); //каталог с программой
PlayList('');
ListBox1.ItemIndex := 0;
Label1.Caption := ListBox1.Items[ListBox1.ItemIndex];}
end;
//щелчок по названию песни
procedure TForm1.ListBox1Click(Sender: TObject);
begin
end;
//щелчок по кнопке Играть
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if SpeedButton1.Caption = 'Играть' then
begin
Play;
SpeedButton1.Caption := 'Стоп';
end
else
begin
SpeedButton1.Caption := 'Играть';
MediaPlayer1.Stop;
Timer1.Enabled := False;
end;
end;
//сигнал от таймера
procedure TForm1.Timer1Timer(Sender: TObject);
Var s : String;
begin
sTrackBar1.max:=MediaPlayer1.Length;
sTrackBar1.Position:=MediaPlayer1.position;
//изменить счетчик времени
if sec < 59
then Inc(sec)
else
begin
sec := 0;
Inc(min);
end;
//вывести время воспроизведения
Label2.Caption := IntToStr(min) + ':';
if sec < 10 then
Label2.Caption := Label2.Caption + '0' + IntToStr(sec)
else
Label2.Caption := Label2.Caption + IntToStr(sec);
//если воспроизведение текущей композиции не завершено
if MediaPlayer1.Position < MediaPlayer1.Length
then Exit;
//воспроизведение текущей композиции закончено
Timer1.Enabled := False;
MediaPlayer1.Stop;
if ListBox1.ItemIndex < ListBox1.Count - 1 then
begin
ListBox1.ItemIndex := ListBox1.ItemIndex + 1;
Play;
end;
if (ListBox1.ItemIndex = ListBox1.Count - 1) and sCheckBox1.Checked = True then
begin
ListBox1.ItemIndex := 0;
Play;
end;
begin
end;
end;
procedure TForm1.ShellTreeView1Change(Sender: TObject; Node: TTreeNode);
begin
cDir:=ShellTreeView1.Path+'/';
PlayList(cDir);
If ListBox1.Items.Count > 0 Then
Begin
ListBox1.ItemIndex := 0;
Label1.Caption := ListBox1.Items[ListBox1.ItemIndex];
End;
end;
а у меня вопрос до тебя: этот код с id3 tag работает?