home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Multi-CD Magazin 1993 January
/
MultiCDMagazin0193_2ndEd.bin
/
cdplayer
/
cdisc.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-06
|
7KB
|
246 lines
UNIT CDISC;
INTERFACE
USES WINTYPES,STRINGS,MMSYSTEM,COMMON;
Type TCDFailProc = Procedure (dwRC:LongInt; pRC:pChar);
Type PCompactDisc = ^TCompactDisc;
TCompactDisc = Object
fpCDFailProc : TCDFailProc;
hParent:HWND;
hDisc:Word;
Constructor Init (hAParent:HWND);
Destructor Done; VIRTUAL;
Function SetFailProc (fpFP:TCDFailProc):Integer;
Function IsPresent:Boolean;
Function IsPlaying:Boolean;
Function Stop:Integer;
Function Play (pszFrom:pChar):Integer;
Function Eject:Integer;
Function GetDiscLength:pChar;
Function GetTrackCount:pChar;
Function GetTrackLength (szTrack:TCharArray):pChar;
Function GetCurrentTrack:pChar;
Function GetCurrentTrackTime:pChar;
PRIVATE
Procedure Failure (dwRC:LongInt);
Function AsStr (i,iW:Integer):pChar;
End;
IMPLEMENTATION
Procedure FailProc (dwRC:LongInt; pRC:pChar);FAR;
Begin;
{ FEHLER AUSSITZEN... }
End;
Constructor TCompactDisc.Init (hAParent:HWND);
Var mciOpenPrm : TMCI_OPEN_PARMS;
mciSetPrm : TMCI_SET_PARMS;
dw : LongInt;
Begin;
fpCDFailProc:=FailProc;
hParent:=hAParent;
{ TRY TO OPEN CD }
mciOpenPrm.DWCALLBACK:=0;
mciOpenPrm.LPSTRDEVICETYPE:='CDAUDIO';
dw:=mciSendCommand (0,MCI_OPEN,MCI_OPEN_TYPE,LONGINT(@mciOpenPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
{ WE CAN OPEN, SO GET THE DEVICE ID }
hDisc:=mciOpenPrm.WDEVICEID;
{ TRY TO SET TIME FORMAT }
mciSetPrm.DWCALLBACK:=0;
mciSetPrm.DWTIMEFORMAT:=MCI_FORMAT_TMSF;
dw:=mciSendCommand (hDisc,MCI_SET,MCI_SET_TIME_FORMAT,LONGINT(@mciSetPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
End;
Destructor TCompactDisc.Done;
Var mciGenPrm : TMCI_GENERIC_PARMS;
Begin;
mciGenPrm.DWCALLBACK:=0;
mciSendCommand (hDisc,MCI_CLOSE,MCI_WAIT,LONGINT(@mciGenPrm));
End;
Function TCompactDisc.Stop:Integer;
Var mciGenPrm : TMCI_GENERIC_PARMS;
Begin;
mciGenPrm.DWCALLBACK:=0;
mciSendCommand (hDisc,MCI_STOP,MCI_WAIT,LONGINT(@mciGenPrm));
Stop:=0;
End;
Function TCompactDisc.Eject:Integer;
Var mciSetPrm : TMCI_SET_PARMS;
Begin;
mciSendCommand (hDisc,MCI_SET,MCI_SET_DOOR_OPEN,LONGINT(@mciSetPrm));
Eject:=0;
End;
Function TCompactDisc.GetTrackLength (szTrack:TCharArray):pChar;
Var mciStatusPrm : TMCI_STATUS_PARMS;
xbuf,buf : TCharArray;
liTime,dw : LongInt;
rc : Integer;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_LENGTH;
Val (szTrack,mciStatusPrm.DWTRACK,rc);
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM OR MCI_TRACK,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
liTime:=mciStatusPrm.DWRETURN;
StrCopy (buf,AsStr(MCI_MSF_MINUTE(liTime),2)); StrCat (buf,':');
StrCat (buf,AsStr(MCI_MSF_SECOND(liTime),2));
GetTrackLength:=buf;
End;
Function TCompactDisc.GetDiscLength:pChar;
Var mciStatusPrm : TMCI_STATUS_PARMS;
buf : TCharArray;
liTime,dw : LongInt;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_LENGTH;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
liTime:=mciStatusPrm.DWRETURN;
StrCopy (buf,AsStr(MCI_MSF_MINUTE(liTime),2)); StrCat (buf,':');
StrCat (buf,AsStr(MCI_MSF_SECOND(liTime),2));
GetDiscLength:=buf;
End;
Function TCompactDisc.GetTrackCount:pChar;
Var mciStatusPrm : TMCI_STATUS_PARMS;
buf : TCharArray;
liTC,dw : LongInt;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_NUMBER_OF_TRACKS;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
liTC:=mciStatusPrm.DWRETURN;
Str (liTC:2,buf);
If (buf[0]=' ') Then buf[0]:='0';
GetTrackCount:=buf;
End;
Function TCompactDisc.IsPlaying:Boolean;
Var mciStatusPrm : TMCI_STATUS_PARMS;
dw : LongInt;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_MODE;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
IsPlaying:=(mciStatusPrm.DWRETURN=MCI_MODE_PLAY);
End;
Function TCompactDisc.IsPresent:Boolean;
Var mciStatusPrm : TMCI_STATUS_PARMS;
dw : LongInt;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_MEDIA_PRESENT;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
IsPresent:=(mciStatusPrm.DWRETURN<>0);
End;
Function TCompactDisc.Play (pszFrom:pChar):Integer;
Var mciPlayPrm : TMCI_PLAY_PARMS;
dw : LongInt;
iFrom,rc : Integer;
Begin;
Val (pszFrom,iFrom,rc);
mciPlayPrm.DWCALLBACK:=hParent;
mciPlayPrm.DWFROM:=MCI_MAKE_TMSF (iFrom,0,0,0);
dw:=mciSendCommand (hDisc,MCI_PLAY,MCI_FROM OR MCI_NOTIFY,LONGINT(@mciPlayPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
Play:=0;
End;
Function TCompactDisc.GetCurrentTrack:pChar;
Var mciStatusPrm : TMCI_STATUS_PARMS;
buf : TCharArray;
dw : LongInt;
iTrk : Integer;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_CURRENT_TRACK;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
iTrk:=mciStatusPrm.DWRETURN;
Str (iTrk:2,buf); If (buf[0]=' ') Then buf[0]:='0';
GetCurrentTrack:=buf;
End;
Function TCompactDisc.GetCurrentTrackTime:pChar;
Var mciStatusPrm : TMCI_STATUS_PARMS;
dw : LongInt;
buf : TCharArray;
Begin;
mciStatusPrm.DWCALLBACK:=0;
mciStatusPrm.DWITEM:=MCI_STATUS_POSITION;
dw:=mciSendCommand (hDisc,MCI_STATUS,MCI_STATUS_ITEM,LONGINT(@mciStatusPrm));
If (dw<>0) Then Begin; Failure (dw); EXIT; End;
StrCopy (buf,AsStr(MCI_TMSF_MINUTE(mciStatusPrm.DWRETURN),2)); StrCat (buf,':');
StrCat (buf,AsStr(MCI_TMSF_SECOND(mciStatusPrm.DWRETURN),2));
GetCurrentTrackTime:=buf;
End;
Function TCompactDisc.AsStr (i,iW:Integer):pChar;
Var buf:TCharArray;
s:String;
Begin;
Str (i:iW,s);
While (Pos(' ',s)<>0) Do s[Pos(' ',s)]:='0';
AsStr:=StrPCopy(buf,s);
End;
Function TCompactDisc.SetFailProc (fpFP:TCDFailProc):Integer;
Begin;
fpCDFailProc:=fpFP;
End;
Procedure TCompactDisc.Failure (dwRC:LongInt);
Var szRC:TCharArray;
Begin;
mciGetErrorString (dwRC,szRC,SizeOf(szRC)-1);
fpCDFailProc (dwRC,szRC);
End;
END.