码迷,mamicode.com
首页 > 其他好文 > 详细

媒体播放器

时间:2015-01-20 17:08:42      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

 

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.

 

技术分享

 

媒体播放器

标签:

原文地址:http://www.cnblogs.com/thrive/p/4236324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!