DelphiFAQ Home Search:

Determine current CD track of TMediaPlayer

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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.
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html

Comments:

2012-11-12, 03:52:59
coach001 from United States  
2018-02-01, 23:20:02
MarkHelton from India  
Nice update to the release page! While on the surface it looks similar, we have made lots of small improvements under the hood and a completely new media player that we'd love to tell you about! The media player now launches at the bottom of the page so you can continue using it. Anyways Thank you so much for this submit and got many ideas from it. All bloggers should have the responsibility to contribute genuine contents.
Ref: https://waltessays.com/

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: