X
xzb_97
Unregistered / Unconfirmed
GUEST, unregistred user!
我想用MediaPlayer组件播放MP3文件,源代码如下:
procedure TForm1.play(tindex:Integer);
begin
with MediaPlayer1 do
begin
Panel2.Repaint;
FileName:=ListBox1.Items.Strings[tindex];
DeviceType:=dtAutoSelect;
Display:=Panel2;
// Close;
Open;
Play;
ListBox1Click(Self);
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
ListBox1.Items:=OpenDialog1.Files;
ListBox1.ItemIndex:=0;
index:=ListBox1.ItemIndex;
MediaPlayer1.EnabledButtons:=[btPlay];
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
index:=ListBox1.ItemIndex;
if (ListBox1.Items.Count>1) then
begin
if index=0 then
MediaPlayer1.EnabledButtons:=[btPlay,btStop,btStep,btBack,btPause,btNext]
else if index=ListBox1.Items.Count-1 then
MediaPlayer1.EnabledButtons:=[btPrev,btPlay,btStop,btStep,btBack,btPause]
else
MediaPlayer1.EnabledButtons:=[btPrev,btPause,btPlay,btStop,btStep,btBack,btNext];
end
else
begin
MediaPlayer1.EnabledButtons:=[btPlay,btStop,btStep,btBack,btPause];
end;
end;
procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
if Button= btPlay then
begin
play(index);
end;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
Close;
end;
end.
procedure TForm1.play(tindex:Integer);
begin
with MediaPlayer1 do
begin
Panel2.Repaint;
FileName:=ListBox1.Items.Strings[tindex];
DeviceType:=dtAutoSelect;
Display:=Panel2;
// Close;
Open;
Play;
ListBox1Click(Self);
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
ListBox1.Items:=OpenDialog1.Files;
ListBox1.ItemIndex:=0;
index:=ListBox1.ItemIndex;
MediaPlayer1.EnabledButtons:=[btPlay];
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
index:=ListBox1.ItemIndex;
if (ListBox1.Items.Count>1) then
begin
if index=0 then
MediaPlayer1.EnabledButtons:=[btPlay,btStop,btStep,btBack,btPause,btNext]
else if index=ListBox1.Items.Count-1 then
MediaPlayer1.EnabledButtons:=[btPrev,btPlay,btStop,btStep,btBack,btPause]
else
MediaPlayer1.EnabledButtons:=[btPrev,btPause,btPlay,btStop,btStep,btBack,btNext];
end
else
begin
MediaPlayer1.EnabledButtons:=[btPlay,btStop,btStep,btBack,btPause];
end;
end;
procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
if Button= btPlay then
begin
play(index);
end;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
Close;
end;
end.