How to open the CD tray programmatically ?

Thursday, October 07 2004 @ 06:44 AM UTC

Contributed by: cocoa

How can I open the CD Tray with cocoa / objective-c. I would like to recreate the functionality of the iTunes eject button.

First don't forget: there is no *the* CD tray. You may have several CD/DVD drives, some have trays, some not (slot loading), etc.

You need to link to the disc recording framework:

#import <DiscRecording/DRDevice.h>
NSArray	*devices = [DRDevice devices]	;
NSEnumerator *aEnum = [devices objectEnumerator];	
DRDevice *aDevice	;
	while ((aDevice = [aEnum nextObject]) != nil) {
		if ([[[aDevice info] objectForKey:DRDeviceLoadingMechanismCanOpenKey] boolValue]) {
			// there are also DRDeviceLoadingMechanismCanInjectKey and DRDeviceLoadingMechanismCanEjectKey
			// the device supports openTray and closeTray
			[aDevice openTray] ;


			[aDevice closeTray] ;