首页 > 代码库 > 媒体播放器
媒体播放器
unit Uni_musicPlayer;interfaceuses 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.
媒体播放器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。