Open/close the cd tray  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 06/09/99

Tip accessed 590 times

 


Add 'MMSystem' in the uses of your form


 	procedure OpenCd(AOpen:Boolean);
 	const
   		DoPlay : array[Boolean] of String =
 	               ('Set cdaudio door closed wait',
 		      	'Set cdaudio door open wait');
 	var
 	  MyError       : LongInt;
 	  MyErrorString : array[0..MAXERRORLENGTH - 1] of char;
 	begin
 	  MyError := mciSendString(pChar(DoPlay[AOpen]), nil, 0, 0);
 	  if MyError <> 0 then
 	  begin
 	    MciGetErrorString(MyError,MyErrorString,MAXERRORLENGTH - 1);
 	    Showmessage(MyErrorString);
 	    Exit;
 	  end;
 	end;




To open the CD:


    OpenCd(TRUE);




To close the CD:


    OpenCd(FALSE);





The previous tip works very well, but if we have more than an unit of CD it doesn't allow to select which to open up.
For that we will use this other code:

  • Add 'MPlayer' in the uses of your form


     procedure TForm1.Button1Click(Sender: TObject);
    
     procedure AbreCD(Disco : char);
     var
       Tokata : TMediaPlayer;
     begin
       Tokata := TMediaPlayer.Create(nil);
       with Tokata do
       begin
         Parent := Self;
         Visible := FALSE;
         Shareable := TRUE;
         DeviceType := dtCDAudio;
         FileName := Disco + ':';
         Wait:=FALSE;
         Open;
         Eject;
         Close;
         Free;
       end;
     end;
    
     begin
       AbreCD('F');
     end;
    




    Updated at 23/08/99 (Humm.. Today is my birthday!)
    Added the second example


    Updated at 06/09/99
    Uses MMSystem missing...