PDA

View Full Version : SAMPLE: CDAudio


Desmond
09-27-2005, 09:58 AM
Hello,

This sample project showcases the CDAudio plugin.

Skills Used: CD, CDA, CDAudio, Timer.

rhosk
10-05-2005, 07:25 AM
I've been playing around with this, and although it works great...on my system, I have 2 CDROM drives and it has a hard time determining which drive a CD is in.

Is there a way to enumerate the drives and actually choose the one (automatically) that has a CD inserted? I tried to break out of the for loop, but it still won't recognize that a CD is/is not inserted. Nothing urgent, just messin' around.

Desmond
10-05-2005, 09:42 AM
Hello rhosk,

Try this:

-- Get all system drives
tDrives = Drive.Enumerate();

-- Initialize loaded variable
bLoaded = false;

-- Loop through drive table
for nIndex, sDrive in tDrives do
-- Get the type of the current drive
nType = Drive.GetType(sDrive);

-- Check if the current drive is a CD drive
if nType == DRIVE_CDROM then
-- Attempt to load a CD from the current drive
CDAudio.LoadCD(sDrive);

-- Get the last reported error
err = Application.GetLastError();

-- Check if the error is related to the load failing
if (err == CDAudio.ERR_NOT_CD_DRIVE) or (err == CDAudio.ERR_NO_CD_IN_DRIVE) then
-- The specified drive either has no cd, or is not a cd drive, do whatever here
elseif (err == CDAudio.OK) then
-- The cd was loaded successfully
bLoaded = true;
else
-- The CD was not loaded successfully
end
end
end

if bLoaded then
-- There is a CD that has been loaded by the CDAudio plugin, do whatever here
else
-- NO CD IS LOADED, ALERT THE USER
Dialog.Message("ERROR", "No CD was found.");
end

I don't have an audio CD here to test with, so the above has only been tested with the base-case (ie. no CD). Give 'er a shot and let me know!

rhosk
10-05-2005, 10:43 AM
That worked perfect, thanks :yes

Desmond
10-05-2005, 10:54 AM
Excellent. Happy to help!

Schmidl
12-31-2005, 06:30 AM
Thanks to Desmond for the sample. But I always get that error attached :wow. Why?

And where do I have to put the CD check script?

Cheers
Schmidl

rhosk
12-31-2005, 06:46 AM
Make sure you have the plugin "CDAudio" checked :)

Schmidl
12-31-2005, 07:03 AM
:o thank you :yes (I should think before I write ;) )

Schmidl

Schmidl
12-31-2005, 08:38 AM
But there is still the last question: Where do I have to put the drive-check-code from Desmond postet on 10-05-2005? Page on show, before the script of the play button...

Schmidl

TJ_Tigger
12-31-2005, 12:14 PM
I guess it depends on when the Audio will start to play. You could place that code in the On Show event and then if an Audio CD is not detected you can disable the Play Audio button. Or you can have it on the Play button and if no Audio CD is found then serve back an error to the user.

Tigg

markczajka
01-24-2007, 03:58 PM
Can the CD Audio sample be reposted?