Audio CD

From: "Chris Rankin" <RankinC@Logica.com>

Vincent Oostindie <vincent.oostindie@tip.nl> wrote

> * How do I get the unique number from an audio CD in the CD-ROM drive?

 


const

  MCI_INFO_PRODUCT                = $00000100;

  MCI_INFO_FILE                   = $00000200;

  MCI_INFO_MEDIA_UPC              = $00000400;

  MCI_INFO_MEDIA_IDENTITY         = $00000800;

  MCI_INFO_NAME                   = $00001000;

  MCI_INFO_COPYRIGHT              = $00002000;

 

{ parameter block for MCI_INFO command message }

type

  PMCI_Info_ParmsA = ^TMCI_Info_ParmsA;

  PMCI_Info_ParmsW = ^TMCI_Info_ParmsW;

  PMCI_Info_Parms = PMCI_Info_ParmsA;

  TMCI_Info_ParmsA = record

    dwCallback: DWORD;

    lpstrReturn: PAnsiChar;

    dwRetSize: DWORD;

  end;

  TMCI_Info_ParmsW = record

    dwCallback: DWORD;

    lpstrReturn: PWideChar;

    dwRetSize: DWORD;

  end;

  TMCI_Info_Parms = TMCI_Info_ParmsA;

 


These are the buffers you want: the identifier is returned as a string of decimal digits by the MCI_INFO_MEDIA_IDENTITY function. You should be able to cross-reference this with the online help (Win32 and TMediaPlayer component).

how to eject and close CD-Drive?

 

From: Christian Piene Gundersen <j.c.p.gundersen@jusstud.uio.no>

ClaWenkel wrote:

>

> Is there any API command in Delphi2 to eject AND CLOSE the CD-ROM Drive

> physically e.g. by clicking on a button? I don't want to use the

> TMediaPlayer component (which can only eject...)

> thanks in advance, ClaWenkel

To open the CD-ROM:

 


        mciSendString('Set cdaudio door open wait', nil, 0, handle);

 


To close the CD-ROM:

 


        mciSendString('Set cdaudio door closed wait', nil, 0, handle);

 


Remember to include the MMSystem unit in your uses clause.

CDROM drives library

 

From: "Jason Wallace" <DarkElf@SLSoftware.reno.nv.us>

GetCD_ID returns the serial number of the CD (as CDPLAYER.EXE does...)

GetCD_Label returns the label of the CD (which will either be a "DOS label", 'AUDIO CD' or 'No CD Present'

FindFirstCDROM returns the first CD Rom it finds (for instance 'D:\') -- it uses the ListDrives function (which returns a TStringList of all available drives on a given PC....)

As for the rest: Win95 uses AutoPlay which, if it's label is 'AUDIO CD' automatically starts the CD player, or if it returns a "DOS Label" it looks for the file 'Autorun.ini" (or .Inf (always forget which...)) and goes from there (take a look in that file. 90% of the time you'll see 'OPEN = xxxxx' (where xxx is the file Autoplay starts when the CD is inserted and 'ICON = xxxxx' which is the icon Autoplay will use..)

 


function GetCD_ID(WhichDrive: string): string;

var

  VolumeName    : array[0..255] of char;

  FileSystemType   : array[0..255] of char;

  SerialNum    : DWORD;

  MaxFilenameLength   : DWORD;

  Flags     : DWORD;

begin

  if (GetVolumeInformation(PChar(WhichDrive),

                           VolumeName,

                           256,

                           @SerialNum,

                           MaxFilenameLength,

                           Flags,

                           FileSystemType,

                           256)) then

  Result := (IntToHex(SerialNum shr 16, 3) +

             IntToHex((SerialNum shl 16) shr 16, 4));

end;

 

function GetCD_Label(WhichDrive: string): string;

var

  VolumeName    : array[0..255] of char;

  FileSystemType   : array[0..255] of char;

  SerialNum    : DWORD;

  MaxFilenameLength   : DWORD;

  Flags     : DWORD;

begin

  Result := 'No CD Present';

  if (GetVolumeInformation(PChar(WhichDrive),

                           VolumeName,

                           256,

                           @SerialNum,

                           MaxFilenameLength,

                           Flags,

                           FileSystemType,

                           256)) then

  Result := VolumeName;

end;

 

function FindFirstCDROM: shortstring;

var

  AList                         : TStringList;

  Counter                       : integer;

begin

  Result := 'no CDROM present';

  AList := TStringList.Create;

  ListDrives(AList);

  for Counter := 0 to AList.Count-1 do

    if GetDriveType(PChar(Alist.Strings[Counter])) = DRIVE_CDROM then

      Result := Alist.Strings[Counter]

end;

 

procedure ListDrives(Strings: TStringList);

const BufSize = 256;

var

  Buffer                    : PChar;

  P                            : PChar;

begin

  GetMem(Buffer, BufSize);

  try

    Strings.BeginUpdate;

    try

      Strings.Clear;

      if GetLogicalDriveStrings(BufSize, Buffer) <> 0 then begin

        P := Buffer;

        while P^ <> #0 do begin

          Strings.Add(P);

          Inc(P, StrLen(P) + 1);

        end;

      end;

    finally

      Strings.EndUpdate;

    end;

  finally

    FreeMem(Buffer, BufSize);

  end;