Solved

CD Track List

Posted on 1998-10-09
34
199 Views
Last Modified: 2010-04-06
How can I provide a tracklist for audio CD's? I'm fairly new to this and have tried several ways to no avail.
0
Comment
Question by:xpher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 11
  • 5
  • +1
34 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1342341
You can retreive the track list and their positions as follows;

Say we have a list box called listbox1, and mediaplayer1

procedure TForm1.ShowTracksButtonClicked(Sender:TObject);
var
  i : integer;
  M : TMediaPlayer;
  T : Longint;
begin
 M := TMediaPlayer1;
 with M do
   if DeviceType = dtCDAudio then
   begin
     TimeFormat := tfTMSF;
      for i:=0 to M.Tracks - 1 do
      begin
          T :=  M.TrackPosition[i];
          ListBox1.Items.Add(Format('Track %d = %02d:%02d:%02d',
             [mci_TMSF_Hour(T),mci_TMSF_Minute(T),mci_TMSF_Second(T)]);
      end;
   end;
end;

regards, igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1342342
Sorry change
  ListBox1.Items.Add(Format('Track %d = %02d:%02d:%02d',
                 [mci_TMSF_Hour(T),mci_TMSF_Minute(T),mci_TMSF_Second(T)]);
to
 ListBox1.Items.Add(Format('Track %d = %02d:%02d:%02d',
                 [i, mci_TMSF_Hour(T),mci_TMSF_Minute(T),mci_TMSF_Second(T)]);
0
 
LVL 1

Author Comment

by:xpher
ID: 1342343
Thanks for the response inter but I can't seem to get it to work.
I am using Delphi 2, does this make a difference?

All I need to stop tearing my hair out is a track list that I can
use to choose which track to play. (Or maybe I'll just give up this Delphi thing!)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:xpher
ID: 1342344
Since my last comment I have looked at it again, but it still doesn,t provide a clean solution. Had to change the Hour from TMSF to HMS. Times are wrong for tracks and it creates a 'Track00'.
Still can't get it to play from a selected track from the list.
Here's hoping.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342345
You need to drop a TMediaPlayer component on your form B4 you try to run this code... And this code needs to be assigned to an OnClick() of a button, and you also need to have a listbox on your form...

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:xpher
ID: 1342346
Thanks viktornet but i've done that. How do I click on a track in the listbox and get it to play?
0
 
LVL 5

Expert Comment

by:inter
ID: 1342347
Ok then,
If you can able to get the above work(i.e. you can see the tracks and its positions in the list do the following:
NOTE: Clear listbox before calling the routine that fills listbox:

// this one seeks to specified track of the media player M provided
// that an audio CD is loaded
procedure SeekToTrack(M : TMediaPlayer; Trac, Minute, Second: Byte);
begin
  with M do
   if DeviceType = dtCDAudio then
   begin
     // we set the time to Track Minute Second Frame Format
     TimeFormat := tfTMSF;
     // This macro makes up a position from vars Frame is 0
     // for CDs
     Position := mci_Make_TMSF(Trac, Minute, Second,0);
   end;
end;

procedure TForm1.ListBox1Clicked(Sender:TObject);
begin
   MediaPlayer1.Stop;
   if ListBox1.ItemIndex <> -1 then
   begin
      // seek the begining of the track
      SeekToTrack(MediaPlayer1, ListBox1.ItemIndex, 0, 0);
      MediaPlayer1.Play;
   end;
end;

may this works, igor
0
 
LVL 1

Author Comment

by:xpher
ID: 1342348
Thanks for the help igor, but I think I might give it up as a hobby.
1) The tracklist (ListBox) starts at Track00 (not Track01).
   Track00 time is total CD time. It also plays the same track as Track01. This then means that if I have a CD with 16 tracks it lists from Track00 to Track15, I lose the last track altogether.
 
2) The times next to track are not times i.e they display like
             Track01=01:00:00;
by removing Hour it becomes i.e. Track01=00:00

I've tried various alterations and looked in books but no joy.

Many thanks
Chris.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342349
Hello Chris.... Just try changing this line->

ListBox1.Items.Add(Format('Track %d = %02d:%02d:%02d',
  [i, mci_TMSF_Hour(T),mci_TMSF_Minute(T),mci_TMSF_Second(T)]);

to this one->

ListBox1.Items.Add(Format('Track %d = %02d:%02d:%02d',
  [i+1, mci_TMSF_Hour(T),mci_TMSF_Minute(T),mci_TMSF_Second(T)]);

Hope this helps you get the tracks right :-)

Regards,
Viktor Ivanov



0
 
LVL 1

Author Comment

by:xpher
ID: 1342350
Thanks for the help Viktor but I've tried adding +1 here and yes the list starts at Track01 but the problem still persists.
This is the way the list appears:
   Track01=50:66 (This plays the whole CD!, Time depends onCD)
        Track02=00:00 (This is the first track on CD)
            and so on.

This is my code as it stands, it also includes for labels etc.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer, ExtCtrls, MMSystem, Buttons;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    ListBox1: TListBox;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    SpeedButton1: TSpeedButton;
    procedure SeekToTrack(M : TMediaPlayer; Trac, Minute, Second: Byte);
  procedure ListBox1Clicked(Sender:TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure ListBox1Enter(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.SeekToTrack(M : TMediaPlayer; Trac, Minute, Second: Byte);
begin
  with M do
   if DeviceType = dtCDAudio then
   begin
     TimeFormat := tfTMSF;
     Position := mci_Make_TMSF(Trac, Minute, Second,0);
   end;
end;

procedure TForm1.ListBox1Clicked(Sender:TObject);
begin
   MediaPlayer1.Stop;
   if ListBox1.ItemIndex <> -1 then
   begin
      SeekToTrack(MediaPlayer1, ListBox1.ItemIndex, 0, 0);
      MediaPlayer1.Play;
   end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
   Track, Minute, Second: byte;
begin
with MediaPlayer1 do
begin
Track := mci_TMSF_Track(Position);
Minute := mci_TMSF_Minute(Position);
Second := mci_TMSF_Second(Position);
Label1.Caption := Format('%.2d',[Track]);
Label2.Caption := Format('%.2d:%.2d',[Minute, Second]);
end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
 MediaPlayer1.Stop;
   if ListBox1.ItemIndex <> -1 then
   begin
      SeekToTrack(MediaPlayer1, ListBox1.ItemIndex, 0, 0);
      MediaPlayer1.Play;
   end;
end;

procedure TForm1.ListBox1Enter(Sender: TObject);
var
   i: integer;
   M: TMediaPlayer;
   T: Longint;
begin
ListBox1.Clear;
     M := MediaPlayer1;
     with M do
          if DeviceType = dtCDAudio then
     begin
          TimeFormat := tfTMSF;
          for i:=0 to M.Tracks -1 do
     begin
     T := M.TrackPosition[i];
     ListBox1.Items.Add(Format('Track %.2d = %.2d:%.2d',
                    [i+1,mci_TMSF_Minute(T),mci_TMSF_Second(T)]));
     end;
     end;
     end;

end.

Thanks again (and you igor)
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342351
Ok, it seems like the tracks start from 1 to TracksCount and not from 0 to TracksCount-1 .... I'm not sure but it's worth trying.... Here is what you should try changing....

Find this code->

for i:=0 to M.Tracks -1 do begin
  T := M.TrackPosition[i];
  ListBox1.Items.Add(Format('Track %.2d = %.2d:%.2d',
    [i+1,mci_TMSF_Minute(T),mci_TMSF_Second(T)]));
end;

and change to this one...

for i:=1 to M.Tracks do begin
  T := M.TrackPosition[i];
  ListBox1.Items.Add(Format('Track %.2d = %.2d:%.2d',
    [i,mci_TMSF_Minute(T),mci_TMSF_Second(T)]));
end;

I hope it works if not I'll take a closer look at the code, or maybe Igor could tell you what eaxctly is the problem when he comes back, if mine doesn't work ;->
0
 
LVL 1

Author Comment

by:xpher
ID: 1342352
i've tried this and similar but it just creates alist starting from Track01 (which plays the whole CD), Track02on the list is actually track1 on the CD and I am a track short at the end.

I've been trying to experiment with the idea of hiding the listbox and copying it into a combo box without copying the track00. not much success here either so far. i know it seems like a cheat but if it would work so what.

Thanks again
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342353
Ok, then here is what you do......Use the old code just change a little bit...
Use this instead of the one I gave you b4

for i := 0 to M.Tracks -1 do begin
       T := M.TrackPosition[i];
       ListBox1.Items.Add(Format('Track %.2d = %.2d:%.2d',
         [i+1,mci_TMSF_Minute(T),mci_TMSF_Second(T)]));
      ListBox1.Items.Delete(0);//add this to your code..
     end;

That's all...I hope it works this time...

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:xpher
ID: 1342354
Unfortunately this just clears the ListBox.

Thanks anyway
Chris
0
 
LVL 1

Author Comment

by:xpher
ID: 1342355
Unfortunately this just clears the ListBox.

Thanks anyway
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342356
Yeah, it deletes the first item that would be the whole time for the CD, so if it is cleared after you got all tracks everything is got to work fine....

btw- Please tell me what's wrong now...

Viktor
0
 
LVL 1

Author Comment

by:xpher
ID: 1342357
No it deletes everything in the ListBox.
Or am I doing something wrong?

Cheers
Chris
0
 
LVL 1

Author Comment

by:xpher
ID: 1342358
have just been trying MediaPlayer1.Start. I can get it to show 1 in an edit box is there any way to transfer this idea?
I used the line
Edit1.Text := IntToStr(MediaPlayer1.Start);

Here's hoping

Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342359
Just tried

ListBox1.Items.Delete(0);

and it deletes only the first lines as I told you! I don't know why it deletes the whole listbox after you aply this methdo . o O

btw- What do you want to transfer from the Edit1 control??? Please be specific????
0
 
LVL 1

Author Comment

by:xpher
ID: 1342360
I was only using Edit1 to play around with MediaPlayer.Start.
Also I have tried again with delete and it still clears the list box. I'm going to start over again and then see.

Thanks for help
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342361
Please send all source code you got so far, and the events you have assigned it to 10x

Viktor
0
 
LVL 1

Author Comment

by:xpher
ID: 1342362
Here is the code:

{Using Delphi 2
       Decided to use a ComboBox instead of ListBox. CombBox named Tracklist.
       Problem is that track00 shows in list. The code as it stands presents
       all playable tracks + track00}
{****************************************************************************}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  MMSystem, MPlayer, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Tracklist: TComboBox;
    MediaPlayer1: TMediaPlayer;
    procedure TracklistEnter(Sender: TObject);
    procedure SeekToTrack(M : TMediaPlayer; Trac, Minute, Second: Byte);
    procedure TracklistClick(Sender: TObject);
    procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
      var DoDefault: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.TracklistEnter(Sender: TObject);
var
  i : integer;
  M : TMediaPlayer;
  T : Longint;
begin
Tracklist.Clear;
 M := MediaPlayer1;
 with M do
   if DeviceType = dtCDAudio then
   begin
     TimeFormat := tfTMSF;
      for i:=0 to M.Tracks  do
      begin
          T :=  M.TrackPosition[i];
          Tracklist.Items.Add(Format('Track %.2d = %.2d:%.2d',
         [i,mci_TMSF_Minute(T),mci_TMSF_Second(T)]));
         {show track 01 in combo box}
         Tracklist.ItemIndex:=1;
         {Tracklist.Items.Delete(0); --- The offending line}
      end;
   end;
end;


procedure TForm1.SeekToTrack(M : TMediaPlayer; Trac, Minute, Second: Byte);
begin
  with M do
   if DeviceType = dtCDAudio then
   begin
     // we set the time to Track Minute Second Frame Format
     TimeFormat := tfTMSF;
     // This macro makes up a position from vars Frame is 0
     // for CDs
     Position := mci_Make_TMSF(Trac, Minute, Second,0);
   end;
end;

procedure TForm1.TracklistClick(Sender: TObject);
begin
   MediaPlayer1.Stop;
   if Tracklist.ItemIndex <> -1 then
   begin
      // seek the begining of the track
      SeekToTrack(MediaPlayer1, Tracklist.ItemIndex, 0, 0);
   end;
end;

end.

I really appreciate the help, thanks.
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342363
Please send me the rest of the code where you load the music from the CD! 10x

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:xpher
ID: 1342364
Don't understand?

The MediaPlayer1 is set for AutoOpen=True in Object Inspector, and for CDAudio.

The code given above is all I am using at the moment as it is pointless doing anymore with this idea unless I can find a way to get rid of Track00.

So when an audio CD is placed in the drive the MediaPlayer plays it.

Regards
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342365
I don't know but I did that myself and it shows me an error message... I'll check it with more care after I get back from school .. Talk to you later

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:xpher
ID: 1342366
Viktor

If you wish I can put together what I,ve got and create a file for you to download including project file?

Regards
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342367
Yeah that would be great! For my e-mail take a look at my profile. It's there... :-)

btw- Sorry it takes so long but I've never worked with TMediaPlayer or music stuff at all in Delphi... I'll try to do my best though

Regards,
Viktor Ivanov
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1342368
There is an example CD player with full Delphi source at Torry's Delphi Pages, perhaps you can get a hint from it?
Check http://www.torry.ru/samples/samples/abcdplay.zip
0
 
LVL 1

Author Comment

by:xpher
ID: 1342369
DOn't apologise Viktor you've been a great help. Ill be in touch
Cheers
Chris

Thanks BlackMan I'll check it out.
Regards
Chris
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342370
Hello Chris!

Please send me the example app.... I use D4, although I think it will compile.. PLease send me the code so I can check it out...

btw- Try it out b4 you send it so you R sure it works.. 10x

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:xpher
ID: 1342371
Inter

How can I assign the points to you seeing as you got the ball rolling. Viktornet agrees that the points should be yours.

Chris
0
 
LVL 5

Expert Comment

by:inter
ID: 1342372
Ok, thanks but I could not solve your problem, so if you insist just drop a comment(sorry I was out for few days but here now..)

0
 
LVL 1

Author Comment

by:xpher
ID: 1342373
Points to Inter.


xpher
0
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1342374
Thanks to all,
just drop a comment if I can do anything on audio...
regards, igor ;-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question