媒体播放器

 

unit Uni_musicPlayer;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MPlayer, StdCtrls, ExtCtrls, jpeg, RxGIF;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    MediaPlayer1: TMediaPlayer;
    Image1: TImage;
    Image8: TImage;
    Image9: TImage;
    Imgnext: TImage;
    Imgprev: TImage;
    ListBox1: TListBox;
    Panel2: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure FindFiles(APath: String);
    procedure ListBox1Click(Sender: TObject);
    procedure ImgnextClick(Sender: TObject);
    procedure ImgprevClick(Sender: TObject);
    procedure MediaPlayer1Notify(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
begin
 //Image1.Picture.LoadFromFile('images\stop.jpg');
  Image1.Picture.Assign(Image9.Picture);
  ListBox1.Clear;
  FindFiles('music\');
  ListBox1.Selected[0]:=True;
  MediaPlayer1.FileName:='music\'+ListBox1.Items[ListBox1.ItemIndex];
  MediaPlayer1.Open;
end;

procedure TForm1.Image1Click(Sender: TObject);
begin
  if  MediaPlayer1.Mode=mpplaying then
  begin
    MediaPlayer1.Pause;
    Image1.Picture.Assign(Image9.Picture);
  end
  else
   begin
    MediaPlayer1.Display:=Panel2;
    MediaPlayer1.Play;
    Image1.Picture.Assign(Image8.Picture);
    MediaPlayer1.DisplayRect:=Panel2.ClientRect;
   end;  

end;

procedure TForm1.FindFiles(APath: String);
 var
   FSearchRec : TSearchRec;
   FindResult: integer;
 begin
   FindResult := FindFirst(APath+'*.*',faAnyFile+faHidden+faSysFile+faReadOnly,FSearchRec);
  try
     while FindResult = 0 do
    begin
      Listbox1.Items.Add(fsearchrec.Name);
      FindResult := FindNext(FSearchRec);
    end;
   finally
     FindClose(FSearchRec);
   end;
 end;
 
procedure TForm1.ListBox1Click(Sender: TObject);
begin
   MediaPlayer1.FileName:='music\'+ListBox1.Items[ListBox1.ItemIndex];
   MediaPlayer1.Open;
   Image1Click(Image1);  //单击歌曲名后自动播放

end;

procedure TForm1.ImgnextClick(Sender: TObject);
var
  mindex:Integer;
begin
    MediaPlayer1.Close;
   if ListBox1.Items.Count-1>ListBox1.ItemIndex  then
      mindex:=ListBox1.ItemIndex+1
   else
      mindex:=0;
   MediaPlayer1.FileName:='music\'+ListBox1.Items[mIndex];
   ListBox1.Selected[mIndex]:=True;  //选中下一首
   MediaPlayer1.Open;
   Image1Click(Image1);  //单击next 按钮后自动播放

end;

procedure TForm1.ImgprevClick(Sender: TObject);
var
  mindex:Integer;
begin
    MediaPlayer1.Close;
   if ListBox1.ItemIndex=0  then
      mindex:=ListBox1.Items.Count-1
   else
     mindex:=ListBox1.ItemIndex-1;
   MediaPlayer1.FileName:='music\'+ListBox1.Items[mIndex];
   ListBox1.Selected[mIndex]:=True;  //选中上一首
   MediaPlayer1.Open;
   Image1Click(Image1);  //单击next 按钮后自动播放

end;
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
   if MediaPlayer1.position>=MediaPlayer1.length then
       ImgnextClick(Imgprev); //自动播放 ,调用下一首过程
end;

end.

 

 

posted on 2015-01-20 15:55  @冰糖  阅读(187)  评论(0编辑  收藏  举报

导航