ucdplayer.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit ucdplayer;
  2. interface
  3. { This program only provides an example of how to use some of the
  4.   Varian Led Studio components.
  5.   It is not intended to be a fully functional cd player.
  6.   Correct drive letter in the Mediaplayer component to point
  7.   to your cd-rom player device.}
  8. uses
  9.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  10.   MPlayer, MMSystem, VrBlotter, VrClasses, VrGradient, VrNavigator, ExtCtrls,
  11.   VrLeds, VrLabel, VrLcd, StdCtrls, VrGauge, VrImageLed, VrControls,
  12.   VrDesign, VrThreads;
  13. type
  14.   TForm1 = class(TForm)
  15.     MediaPlayer: TMediaPlayer;
  16.     VrBlotter1: TVrBlotter;
  17.     VrGradient: TVrGradient;
  18.     VrNavigator: TVrNavigator;
  19.     VrBlotter: TVrBlotter;
  20.     VrLed: TVrLed;
  21.     VrLabel1: TVrLabel;
  22.     Label5: TLabel;
  23.     VrNumTotalTracks: TVrNum;
  24.     Label6: TLabel;
  25.     VrClockDiskTime: TVrClock;
  26.     Label7: TLabel;
  27.     VrCurTrack: TVrNum;
  28.     Label3: TLabel;
  29.     Label1: TLabel;
  30.     Label2: TLabel;
  31.     Label4: TLabel;
  32.     VrGauge: TVrGauge;
  33.     VrImageLed: TVrImageLed;
  34.     VrClockCurTrackTime: TVrClock;
  35.     VrClockTotalTrackTime: TVrClock;
  36.     VrTimer: TVrTimer;
  37.     VrLabel2: TVrLabel;
  38.     procedure TimerTimer(Sender: TObject);
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure MediaPlayerNotify(Sender: TObject);
  41.     procedure VrNavigatorButtonClick(Sender: TObject;
  42.       ButtonType: TVrButtonType);
  43.     procedure FormDestroy(Sender: TObject);
  44.   private
  45.     FOpen: Boolean;
  46.     procedure OpenAudioDevice;
  47.     procedure CheckDisk;
  48.     procedure CheckPosition;
  49.     procedure ResetControls;
  50.   public
  51.     { Public declarations }
  52.   end;
  53. var
  54.   Form1: TForm1;
  55. implementation
  56. const
  57.   Modes: array[TMPModes] of PChar = ('NOT READY', 'STOPPED', 'PLAYING',
  58.     'RECORDING', 'SEEKING', 'PAUSED', 'OPEN');
  59. {$R *.DFM}
  60. procedure TForm1.FormCreate(Sender: TObject);
  61. begin
  62.   Left := 50;
  63.   Top := 50;
  64.   MediaPlayer.TimeFormat := tfTMSF;
  65.   MediaPlayer.Notify := True;
  66.   MediaPlayer.Wait := False;
  67. end;
  68. procedure TForm1.FormDestroy(Sender: TObject);
  69. begin
  70.   try
  71.     MediaPlayer.Stop;
  72.     MediaPlayer.Close;
  73.   except
  74.   end;
  75. end;
  76. procedure TForm1.OpenAudioDevice;
  77. begin
  78.   try
  79.     MediaPlayer.Close;
  80.     MediaPlayer.Open;
  81.     FOpen := true;
  82.   except
  83.     FOpen := false;
  84.   end;
  85.   VrLed.Active := FOpen;
  86. end;
  87. procedure TForm1.TimerTimer(Sender: TObject);
  88. begin
  89.   if not FOpen then
  90.     OpenAudioDevice
  91.   else
  92.   if MediaPlayer.Mode = mpPlaying then
  93.     CheckPosition;
  94.   MediaPlayerNotify(MediaPlayer);
  95. end;
  96. procedure TForm1.MediaPlayerNotify(Sender: TObject);
  97. begin
  98.   VrLabel1.Caption := Modes[MediaPlayer.Mode];
  99.     case MediaPlayer.Mode of
  100.     mpNotReady:;
  101.     mpStopped:
  102.       begin
  103.         CheckDisk;
  104.         VrImageLed.Active := False;
  105.       end;
  106.     mpPlaying:
  107.       begin
  108.         CheckDisk;
  109.         VrImageLed.Active := True;
  110.       end;
  111.     mpSeeking:;
  112.     mpPaused:;
  113.     mpOpen: ResetControls;
  114.   end;
  115. end;
  116. procedure TForm1.VrNavigatorButtonClick(Sender: TObject;
  117.   ButtonType: TVrButtonType);
  118. begin
  119.   try
  120.     case ButtonType of
  121.       btPower: Application.Terminate;
  122.       btPlay: MediaPlayer.Play;
  123.       btStop: MediaPlayer.Stop;
  124.       btPause: MediaPlayer.Pause;
  125.       btNext: MediaPlayer.Next;
  126.       btPrev: MediaPlayer.Previous;
  127.       btEject: MediaPlayer.Eject;
  128.     end;
  129.     MediaPlayerNotify(MediaPlayer);
  130.   except
  131.   end;
  132. end;
  133. procedure TForm1.CheckDisk;
  134. var
  135.   NTracks, NLen: Integer;
  136. begin
  137.   NTracks := MediaPlayer.Tracks;
  138.   NLen := MediaPlayer.Length;
  139.   VrNumTotalTracks.Value := NTracks;
  140.   VrClockDiskTime.Hours := MCI_MSF_MINUTE(NLen);
  141.   VrClockDiskTime.Minutes := MCI_MSF_SECOND(NLen);
  142. end;
  143. procedure TForm1.CheckPosition;
  144. var
  145.   CurrentTrack, CurrentPos, TrackLen: Integer;
  146.   Mt, Pt, M, S: Integer;
  147. begin
  148.   CurrentPos := MediaPlayer.Position;
  149.   VrClockCurTrackTime.Hours := MCI_TMSF_MINUTE(CurrentPos);
  150.   VrClockCurTrackTime.Minutes := MCI_TMSF_SECOND(CurrentPos);
  151.   CurrentTrack := MCI_TMSF_TRACK (CurrentPos);
  152.   VrCurTrack.Value := CurrentTrack;
  153.   TrackLen := MediaPlayer.TrackLength [CurrentTrack];
  154.   VrClockTotalTrackTime.Hours := MCI_MSF_MINUTE(TrackLen);
  155.   VrClockTotalTrackTime.Minutes := MCI_MSF_SECOND(TrackLen);
  156.   Application.ProcessMessages;
  157.   M := MCI_MSF_MINUTE(TrackLen);
  158.   S :=  MCI_MSF_SECOND(TrackLen);
  159.   Mt := (M * 60) + S;
  160.   M := MCI_TMSF_MINUTE(CurrentPos);
  161.   S := MCI_TMSF_SECOND(CurrentPos);
  162.   Pt := (M * 60) + S;
  163.   VrGauge.MaxValue := Mt;
  164.   VrGauge.Position := Pt;
  165. end;
  166. procedure TForm1.ResetControls;
  167. begin
  168.   VrNumTotalTracks.Value := 0;
  169.   VrClockDiskTime.Hours := 0;
  170.   VrClockDiskTime.Minutes := 0;
  171.   VrClockCurTrackTime.Hours := 0;
  172.   VrClockCurTrackTime.Minutes := 0;
  173.   VrCurTrack.Value := 0;
  174.   VrClockTotalTrackTime.Hours := 0;
  175.   VrClockTotalTrackTime.Minutes := 0;
  176.   VrGauge.Position := 0;
  177. end;
  178. end.