ToggleEjectCDAudio()

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

ToggleEjectCDAudio()

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by GPI.

Small procedure that open the CD, if it closed and closed it, when open.

It's a small trick: EjectCDAudio() waits until the status is changed. When a CD is open and you open it again, it will return fasten that when you open to closed cd.

Code: Select all

InitAudioCD()

Procedure ToggleEjectCDAudio()
  timer1=GetTickCount_()
  EjectAudioCD(1)
  timer1= GetTickCount_()-timer1
  timer2=GetTickCount_()
  EjectAudioCD(1)
  timer2=GetTickCount_()-timer2
  timer=timer1-timer2
  If timer<0:timer=-timer:EndIf
  If timer<100
    EjectAudioCD(0)
  EndIf
EndProcedure

Debug "toogle1"
toggleejectcdaudio()
Debug "toogle2"
toggleejectcdaudio()

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

This code is better, because it free the cd for other applications.

Code: Select all

mciOpenParms.MCI_OPEN_PARMS;
a$="cdaudio"
mciOpenParms\lpstrDeviceType = @a$
dwReturn = mciSendCommand_(0, #MCI_OPEN, #MCI_OPEN_TYPE, mciOpenParms)
If dwreturn =0
  wDeviceID = mciOpenParms\wDeviceID
  timer1=gettickcount_()
  mciSendCommand_(wDeviceID, #MCI_SET, #MCI_SET_DOOR_OPEN ,0)
  timer1= gettickcount_()-timer1
  timer2=gettickcount_()
  mciSendCommand_(wDeviceID, #MCI_SET, #MCI_SET_DOOR_OPEN ,0)
  timer2= gettickcount_()-timer2
  timer=timer1-timer2
  If timer<0:timer=-timer:EndIf
  Debug timer
  If timer<100
    mciSendCommand_(wDeviceID, #MCI_SET, #MCI_SET_DOOR_CLOSED ,0)
  EndIf
  mciSendCommand_(wDeviceID, #MCI_CLOSE, 0, 0)
EndIf

I miss a exitCDAudio() !

I think, that this is the main-problem of nearly every library.

I can init something, but never exit.

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
Post Reply