找传奇、传世资源到传世资源站!

delphi多媒体播放器(可播放mp3文件)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

【例子介绍】

【相关图片】

from clipboard

【源码结构】

unit FPlay;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,FileCtrl, MPlayer, ExtCtrls, ComCtrls, ToolWin, ImgList, Buttons;

type
  TMainForm = class(TForm)
    GroupBox1: TGroupBox;
    Panel1: TPanel;
    FileNameList: TListBox;
    Panel2: TPanel;
    MediaPlayer1: TMediaPlayer;
    AppendButton: TButton;
    Panel3: TPanel;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    FileNumLabel: TPanel;
    GroupBox3: TGroupBox;
    Panel4: TPanel;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    StopButton: TSpeedButton;
    PauseButton: TSpeedButton;
    PlayButton: TSpeedButton;
    OpenDialog1: TOpenDialog;
    FilePathList: TListBox;
    procedure AppendButtonClick(Sender: TObject);
    procedure FileNameListDblClick(Sender: TObject);
    procedure FileNameListKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure PlayButtonClick(Sender: TObject);
    procedure PauseButtonClick(Sender: TObject);
    procedure StopButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure MP3Play;
    Procedure MP3Stop;
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.AppendButtonClick(Sender: TObject);
var
  i:integer;
  MainPath:string;
  FileExt:string;
  FilePath:string;
  FileRec:TSearchRec;
  FileNum:string;
begin
  SelectDirectory('sdf','c',MainPath);
  FilePath:=MainPath;
  FileExt:='\*.mp3';
  MainPath:=MainPath FileExt;
  FindFirst(MainPath,faAnyFile,FileRec);
  if Trim(FileRec.Name)<>'' then
    begin
      FileNum:=IntToStr(FileNameList.Items.count 1);
      if Length(FileNum)<3 then
        begin
          for i:=1 to (3-Length(FileNum)) do
            FileNum:=' ' FileNum;
        end;
      FileNum:=FileNum '.  ';
      FileNameList.Items.Add(FileNum FileRec.Name);
      FilePathList.Items.Add(FilePath);
    end;
  while FindNext(FileRec) = 0 do
    begin
      if Trim(FileRec.Name)<>'' then
        begin
          FileNum:=IntToStr(FileNameList.Items.count 1);
          if Length(FileNum)<3 then
            begin
              for i:=1 to (3-Length(FileNum)) do
                FileNum:=' ' FileNum;
            end;
          FileNum:=FileNum '.  ';
          FileNameList.Items.Add(FileNum FileRec.Name);
          FilePathList.Items.Add(FilePath);
        end;
    end;
  FileNum:=IntToStr(FileNameList.Items.count);
  FileNumLabel.Caption:=Format('共有%s个文件',[FileNum]);
end;

procedure TMainForm.FileNameListDblClick(Sender: TObject);
begin
  MP3Play;
end;

procedure TMainForm.MP3Play;
var
  FileName:string;
begin
  if (Trim(Mediaplayer1.FileName)='') or (MediaPlayer1.Mode=mpPlaying) then
    begin
      if FileNameList.Items.count>0 then
        begin
          FileName:=FileNameList.Items.Strings[FileNameList.itemindex];
          FileName:=Copy(FileName,7,Length(FileName)-6);
          MediaPlayer1.FileName:=FilePathList.Items.Strings[FileNameList.itemindex] '\' FileName;
          MediaPlayer1.Open;
          MediaPlayer1.Play;
        end;
    end
  else
    begin
      MediaPlayer1.Resume;
    end;
end;

procedure TMainForm.FileNameListKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=13 then
    begin
      MP3Play;
    end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
var
  FileNum:string;
begin
  FileNameList.Clear;
  FilePathList.Clear;
  FileNum:=IntToStr(FileNameList.Items.count);
  FileNumLabel.Caption:=Format('共有%s个文件',[FileNum]);
end;

procedure TMainForm.Button3Click(Sender: TObject);
var
  FileNum:string;
  i:integer;
begin
  FileNum:=IntToStr(FileNameList.Items.count 1);
  for i:=1 to 3-Length(FileNum) do
    begin
      FileNum:=' ' FileNum;
    end;
  FileNum:=FileNum '.  ';
  if OpenDialog1.Execute then
    begin
      FileNameList.Items.Add(FileNum ExtractFileName(OpenDialog1.FileName));
      FilePathList.Items.Add(ExtractFilePath(OpenDialog1.FileName));
    end;
  FileNum:=IntToStr(FileNameList.Items.count);
  FileNumLabel.Caption:=Format('共有%s个文件',[FileNum]);
end;

procedure TMainForm.Button2Click(Sender: TObject);
var
  FileNum:string;
begin
  FileNameList.Items.Delete(FileNameList.ItemIndex);
  FilePathList.Items.Delete(FileNameLIst.ItemIndex);
  FileNum:=IntToStr(FileNameList.Items.count);
  FileNumLabel.Caption:=Format('共有%s个文件',[FileNum]);
end;

procedure TMainForm.PlayButtonClick(Sender: TObject);
begin
  MP3Play;
end;

procedure TMainForm.MP3Stop;
begin
  MediaPlayer1.FileName:='';
  MediaPlayer1.Stop;
  MediaPlayer1.Close;
end;

procedure TMainForm.PauseButtonClick(Sender: TObject);
begin
  MediaPlayer1.Pause;
end;

procedure TMainForm.StopButtonClick(Sender: TObject);
begin
  MP3Stop;
end;

end.

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复