对不起,各位,我上面没把问题说清楚,不是媒体播放器,是Flash播放器,我的代码如下,还望各位多帮忙啊!!var s: string; //定义全局变量procedure TFlashPlayer.OpenBtnClick(Sender: TObject); var i: integer; //这部分是打开若干文件并把文件名显示在ListBox里 begin if OpenDialog1.Execute then begin for i:=0 to OpenDialog1.Files.Count-1 do ListBox1.Items.add(ExtractFileName(OpenDialog1.Files[i])); end; end;procedure TFlashPlayer.PlayBtnClick(Sender: TObject); begin //这是控制播放的,按下此按钮,应该开始播放 ShockwaveFlash1.Playing:=true; ShockwaveFlash1.Movie:=s; ShockwaveFlash1.Movie:=ListBox1.Items.Text; end;procedure TFlashPlayer.ListBox1Click(Sender: TObject); begin //把在ListBox里选择的文件名赋值给s s:=ListBox1.Items[ListBox1.ItemIndex]; end;用以上代码,当选择一个文件,点击播放按钮后,无反应。 请各位大虾帮我看看,谢谢了!
procedure TFlashPlayer.OpenBtnClick(Sender: TObject); var i: integer; begin if OpenDialog1.Execute then begin for i:=0 to OpenDialog1.Files.Count-1 do ListBox1.Items.add(ExtractFileName(OpenDialog1.Files[i])); end; s:=ExtractFilePath(OpenDialog1.Files[0]); end;procedure TFlashPlayer.ListBox1Click(Sender: TObject); begin s:=s+ListBox1.Items[ListBox1.ItemIndex]; end;procedure TFlashPlayer.PlayBtnClick(Sender: TObject); begin ShockwaveFlash1.Playing:=true; ShockwaveFlash1.Movie:=s; end;
MediaPlayer1.Play;
MediaPlayer1.FileName:= listbox1.items.text;
MediaPlayer1.Play;
为了省事,我用了filelistbox控件,原理一样,你试试,勿忘
进右下角的 管理 中,放分}unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, MPlayer,FileCtrl, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
MediaPlayer1: TMediaPlayer;
Label1: TLabel;
FileListBox1: TFileListBox;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
procedure FileListBox1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
dir:string;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin
SelectDirectory('选择目录','',dir);
label1.caption:=dir;
form1.FileListBox1.Mask:='*.mpg';
form1.FileListBox1.Directory:=label1.caption;
end;procedure TForm1.FileListBox1Click(Sender: TObject);
beginform1.MediaPlayer1.FileName:=form1.FileListBox1.FileName;
showmessage(form1.MediaPlayer1.FileName);
form1.MediaPlayer1.Open;
form1.MediaPlayer1.Play;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
form1.MediaPlayer1.display:=panel1;
end;end.祝:身体健康,分数和答案同样重要:)
var
i: integer; //这部分是打开若干文件并把文件名显示在ListBox里
begin
if OpenDialog1.Execute then
begin
for i:=0 to OpenDialog1.Files.Count-1 do
ListBox1.Items.add(ExtractFileName(OpenDialog1.Files[i]));
end;
end;procedure TFlashPlayer.PlayBtnClick(Sender: TObject);
begin //这是控制播放的,按下此按钮,应该开始播放
ShockwaveFlash1.Playing:=true;
ShockwaveFlash1.Movie:=s;
ShockwaveFlash1.Movie:=ListBox1.Items.Text;
end;procedure TFlashPlayer.ListBox1Click(Sender: TObject);
begin //把在ListBox里选择的文件名赋值给s
s:=ListBox1.Items[ListBox1.ItemIndex];
end;用以上代码,当选择一个文件,点击播放按钮后,无反应。
请各位大虾帮我看看,谢谢了!
var
i: integer;
begin
if OpenDialog1.Execute then
begin
for i:=0 to OpenDialog1.Files.Count-1 do
ListBox1.Items.add(ExtractFileName(OpenDialog1.Files[i]));
end;
s:=ExtractFilePath(OpenDialog1.Files[0]);
end;procedure TFlashPlayer.ListBox1Click(Sender: TObject);
begin
s:=s+ListBox1.Items[ListBox1.ItemIndex];
end;procedure TFlashPlayer.PlayBtnClick(Sender: TObject);
begin
ShockwaveFlash1.Playing:=true;
ShockwaveFlash1.Movie:=s;
end;