unit pasPCD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, MPlayer, Menus;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    Timer1: TTimer;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    ComboBox1: TComboBox;
    Button8: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button8Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
 procedure TForm1.FormCreate(Sender: TObject);
begin
  with MediaPlayer1 do
    begin
      Visible:=True;
      DeviceType:=dtCDAudio;
      open;
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MediaPlayer1.play;
end;


procedure TForm1.Button3Click(Sender: TObject);
begin
MediaPlayer1.Pause;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
MediaPlayer1.Stop;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
MediaPlayer1.Previous;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
MediaPlayer1.Next;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
MediaPlayer1.Eject;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
     begin
       MediaPlayer1.FileName:=OpenDialog1.FileName;
       MediaPlayer1.Open;
       end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 i,j,k:integer;
 pos1,pos2:longint;
 flag:Boolean;
 str1:string;
begin
  memo1.lines[0]:='总曲目数：'+inttostr(MediaPlayer1.Tracks);
  MediaPlayer1.TimeFormat:=tfMilliseconds;
  pos1:=0;
  pos2:=0;
  flag:=true;
  for i:=0 to MediaPlayer1.Tracks-1 do
    begin
     for j:=0 to i-1 do
       begin
        pos1:=pos1+MediaPlayer1.TrackLength[j];
        pos2:=pos1;
       end;
     pos2:=pos2+MediaPlayer1.TrackLength[i];
     if MediaPlayer1.Position>pos1 then
        begin
         if MediaPlayer1.Position<pos2 then
           begin
         memo1.lines[1]:='正在播放的曲目：第 '+inttostr(i+1)+' 首';
         flag:=False;
          end;
       end;
  end;
  if flag then
    memo1.lines[1]:='正在播放的曲目：第 1 首';
 k:=round(MediaPlayer1.Length/60000);
  memo1.lines[2]:='曲目长度：'+inttostr(k);
  str1:='当前状态： ';
  Case MediaPlayer1.Mode  of
  mpNotReady: Memo1.Lines[3]:=str1+'准备未绪';
  mpStopped: Memo1.Lines[3]:=str1+'已停止';
  mpPlaying: Memo1.Lines[3]:=str1+'正在播放';
  mpRecording: Memo1.Lines[3]:=str1+'正在记录';
  mpSeeking: Memo1.Lines[3]:=str1+'正在搜索';
  mpPaused: Memo1.Lines[3]:=str1+'已暂停';
  mpOpen: Memo1.Lines[3]:=str1+'打开';
  end;
  end;



procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MediaPlayer1.close;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
Close;
end;

end.
