Mega Code Archive

 
Categories / Delphi / Examples
 

Determine current cd track of tmediaplayer

Question: How can I determine the current track of an audio CD played by TMediaPlayer? Answer: The following code will retrieve it from the TMediaPlayer component. If you want to display it on a form, you could put the code in a timer event. You need the unit MMSystem in your uses clause. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, MMSystem, MPlayer, ExtCtrls, StdCtrls; type TForm1 = class(TForm) MediaPlayer1: TMediaPlayer; Timer1: TTimer; Label1: TLabel; Label2: TLabel; procedure Timer1Timer(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Timer1Timer(Sender: TObject); var Trk, Min, Sec: Word; begin with MediaPlayer1 do begin Trk := MCI_TMSF_TRACK(position); Min := MCI_TMSF_MINUTE(position); Sec := MCI_TMSF_SECOND(position); Label1.caption := Format('Track %.2d', [Trk]); Label2.caption := Format('Position %.2d:%.2d', [Min, Sec]); end; end; end.