home *** CD-ROM | disk | FTP | other *** search
- unit MPUnit;
- { PC Plus Sample Program.
- A Simple Media Player for Delphi 2.0
-
- Plays Media files: AVI, WAV, MID, RMI etc.
- also CD Audio disks.
-
- Limitations: Needs more error checking.
- Does not handle empty CD drive or non-Audio CDs.
- No display of track information (e.g. position)
-
- Author: Huw Collingbourne
- }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, MPlayer, Menus;
-
- type
- TForm1 = class(TForm)
- MediaPlayer1: TMediaPlayer;
- Label1: TLabel;
- OpenDialog1: TOpenDialog;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Open1: TMenuItem;
- Exit1: TMenuItem;
- PlayCD1: TMenuItem;
- procedure FormActivate(Sender: TObject);
- procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
- var DoDefault: Boolean);
- procedure Open1Click(Sender: TObject);
- procedure PlayCD1Click(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- const
- MediaDir = '\Windows\Media'; { change if you want a different default dir }
- FormCaption = 'PC Plus Media Player';
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- ChDir(MediaDir); { change to default media directory }
- Form1.Caption := FormCaption;
- end;
-
-
-
- procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
- var DoDefault: Boolean);
- { test the Button parameter to display a descriptive label }
- begin
- case Button of
- btPlay : Label1.Caption := 'Playing';
- btPause: Label1.Caption := 'Paused';
- btStop: Label1.Caption := 'Stopped';
- btNext: Label1.Caption := 'Next';
- btPrev: Label1.Caption := 'Previous';
- btEject: Label1.Caption := 'Eject';
- end;
- end;
-
- procedure TForm1.Open1Click(Sender: TObject);
- { Pop up File dialog. Try to open media file selected }
- begin
- if OpenDialog1.Execute then
- { if a file is selected then...}
- begin
- if MediaPlayer1.Mode = mpPlaying then
- MediaPlayer1.Stop;
- MediaPlayer1.Close;
- MediaPlayer1.Devicetype := dtAutoselect;
- MediaPlayer1.FileName := OpenDialog1.FileName;
- Form1.Caption := ExtractFileName(OpenDialog1.FileName);
- try
- MediaPlayer1.Open;
- except
- MessageDlg(MediaPlayer1.ErrorMessage, mtWarning, [mbOK], 0);
- Label1.Caption := 'No media loaded!';
- end;
- if MediaPlayer1.Error = 0 then
- Label1.Caption := 'Media loaded...';
- end;
- end;
-
- procedure TForm1.PlayCD1Click(Sender: TObject);
- { Open and play CD }
- begin
- if MediaPlayer1.Mode = mpPlaying then
- MediaPlayer1.Stop;
- MediaPlayer1.Close;
- MediaPlayer1.Filename := '';
- MediaPlayer1.Devicetype := dtCDAudio;
- MediaPlayer1.Open;
- MediaPlayer1.Play;
- Label1.Caption := 'Audio CD';
- Form1.Caption := 'Playing CD';
- end;
-
- procedure TForm1.Exit1Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-