Главная страница | назад





Article #17756: Does my CD-ROM Drive contain an Audio CD?

 Question and Answer Database
FAQ2756D.txt Does my CD-ROM Drive contain an Audio CD?
Category :VCL
Platform :All
Product :All 32 bit
Question:
How can I tell if a given CD-ROM Drive contains an
Audio CD?
Answer:
You can use the Windows API function GetDriveType() to
test if the drive is a CD-ROM drive then use the Windows
API function GetVolumeInformation() to test if the
VolumeName is 'Audio CD'.
Example:
function IsAudioCD(Drive : char) : bool;
var
DrivePath : string;
MaximumComponentLength : DWORD;
FileSystemFlags : DWORD;
VolumeName : string;
begin
Result := false;
DrivePath := Drive + ':\';
if GetDriveType(PChar(DrivePath)) <> DRIVE_CDROM then exit;
SetLength(VolumeName, 64);
GetVolumeInformation(PChar(DrivePath),
PChar(VolumeName),
Length(VolumeName),
nil,
MaximumComponentLength,
FileSystemFlags,
nil,
0);
if lStrCmp(PChar(VolumeName),'Audio CD') = 0 then result := true;
end;
function PlayAudioCD(Drive : char) : bool;
var
mp : TMediaPlayer;
begin
result := false;
Application.ProcessMessages;
if not IsAudioCD(Drive) then exit;
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := Drive + ':';
mp.Shareable := true;
mp.Open;
Application.ProcessMessages;
mp.Play;
Application.ProcessMessages;
mp.Close;
Application.ProcessMessages;
mp.free;
result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not PlayAudioCD('D') then
ShowMessage('Not an Audio CD');
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99