MCI.Cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "main.h"
  2. MCIERROR MCISendCommand(MCIDEVICEID IDDevice, UINT uMsg, DWORD fdwCommand, DWORD_PTR dwParam)
  3. {
  4. MCIERROR nErr = mciSendCommand(IDDevice, uMsg, fdwCommand, dwParam);
  5. #if 0
  6. if (nErr)
  7. {
  8. wchar_t szError[256] = {0};
  9. mciGetErrorString(nErr, szError, 256);
  10. MessageBox(NULL,szError,L"MCI CD Error",MB_OK);
  11. }
  12. #endif
  13. return nErr;
  14. }
  15. int isMediaPresent(MCIDEVICEID wDeviceID)
  16. {
  17. MCI_STATUS_PARMS p;
  18. p.dwItem=MCI_STATUS_MEDIA_PRESENT;
  19. if (MCISendCommand(wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD_PTR)&p)) return 1;
  20. return p.dwReturn?1:0;
  21. }
  22. BOOL CDOpen(MCIDEVICEID* lpDeviceID, int device, const wchar_t *alias)
  23. {
  24. //OutputDebugString("Calling cdopen()\n");
  25. MCI_OPEN_PARMS sMCIOpen;
  26. MCI_SET_PARMS sMCISet;
  27. wchar_t zDevice[3]={(wchar_t)device,':',0};
  28. DWORD nErr;
  29. sMCIOpen.dwCallback = 0;
  30. sMCIOpen.wDeviceID = 0;
  31. sMCIOpen.lpstrAlias = alias;
  32. sMCIOpen.lpstrDeviceType = (LPCTSTR) MCI_DEVTYPE_CD_AUDIO;
  33. sMCIOpen.lpstrElementName = zDevice;
  34. nErr = MCISendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE |
  35. MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT |
  36. (alias ? MCI_OPEN_ALIAS : 0), (DWORD_PTR) &sMCIOpen);
  37. if (nErr)
  38. {
  39. nErr = MCISendCommand(0, MCI_OPEN, MCI_OPEN_TYPE |
  40. MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT |
  41. (alias ? MCI_OPEN_ALIAS : 0), (DWORD_PTR) &sMCIOpen);
  42. if (nErr)
  43. {
  44. return FALSE;
  45. }
  46. }
  47. sMCISet.dwTimeFormat = MCI_FORMAT_TMSF;
  48. MCISendCommand (sMCIOpen.wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR) &sMCISet);
  49. *lpDeviceID = sMCIOpen.wDeviceID;
  50. return TRUE;
  51. }
  52. void CDClose(MCIDEVICEID* lpDeviceID)
  53. {
  54. MCI_GENERIC_PARMS sMCIGeneric;
  55. sMCIGeneric.dwCallback = (DWORD_PTR) line.hMainWindow;
  56. MCISendCommand(*lpDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR) &sMCIGeneric);
  57. *lpDeviceID = 0;
  58. }
  59. void CDEject(MCIDEVICEID wDeviceID)
  60. {
  61. MCI_SET_PARMS mciset;
  62. MCISendCommand (wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN,(DWORD_PTR) &mciset);
  63. }
  64. unsigned int CDGetTracks(MCIDEVICEID wDeviceID)
  65. {
  66. MCI_STATUS_PARMS sMCIStatus;
  67. sMCIStatus.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
  68. if (MCISendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT,(DWORD_PTR) &sMCIStatus)) return -1;
  69. return sMCIStatus.dwReturn;
  70. }
  71. unsigned int CDGetCurrTrack(MCIDEVICEID wDeviceID)
  72. {
  73. MCI_STATUS_PARMS sMCIStatus;
  74. sMCIStatus.dwItem = MCI_STATUS_POSITION;
  75. MCISendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT,(DWORD_PTR) &sMCIStatus);
  76. return ((int) MCI_TMSF_TRACK (sMCIStatus.dwReturn));
  77. }
  78. int CDPlay(MCIDEVICEID wDeviceID, unsigned int nTrack, BOOL bResume, unsigned int nMin, unsigned int nSec, unsigned int endms)
  79. {
  80. MCI_PLAY_PARMS sMCIPlay;
  81. unsigned int nActualTrack = nTrack;
  82. sMCIPlay.dwFrom = MCI_MAKE_TMSF (nActualTrack, nMin, nSec, 0);
  83. sMCIPlay.dwTo = MCI_MAKE_TMSF (nActualTrack, endms/60000, (endms/1000)%60,0);
  84. if (!bResume)
  85. {
  86. return MCISendCommand (wDeviceID, MCI_PLAY, MCI_FROM | MCI_TO ,(DWORD_PTR) &sMCIPlay);
  87. }
  88. else
  89. {
  90. return MCISendCommand (wDeviceID, MCI_PLAY, MCI_FROM | MCI_TO, (DWORD_PTR) (LPVOID) &sMCIPlay);
  91. }
  92. }
  93. void CDStop(MCIDEVICEID wDeviceID)
  94. {
  95. MCISendCommand(wDeviceID, MCI_STOP, 0, 0);
  96. }
  97. void CDPause(MCIDEVICEID wDeviceID)
  98. {
  99. MCISendCommand(wDeviceID, MCI_PAUSE, 0,0);
  100. }
  101. unsigned int CDGetTrackLength(MCIDEVICEID wDeviceID, unsigned int nTrack)
  102. {
  103. MCI_STATUS_PARMS sMCIStatus;
  104. int r;
  105. sMCIStatus.dwItem = MCI_STATUS_POSITION ;
  106. sMCIStatus.dwTrack = nTrack+1;
  107. if (MCISendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,(DWORD_PTR) &sMCIStatus)) // if error than last track
  108. {
  109. sMCIStatus.dwItem = MCI_STATUS_LENGTH;
  110. sMCIStatus.dwTrack = nTrack;
  111. if (MCISendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,(DWORD_PTR) &sMCIStatus)) return -1000;
  112. return sMCIStatus.dwReturn;
  113. }
  114. r=sMCIStatus.dwReturn;
  115. sMCIStatus.dwItem = MCI_STATUS_POSITION ;
  116. sMCIStatus.dwTrack = nTrack;
  117. if (MCISendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,(DWORD_PTR) &sMCIStatus)) return -1000;
  118. return r-sMCIStatus.dwReturn;
  119. }
  120. BOOL CDID(MCIDEVICEID wDeviceID, wchar_t *id, size_t len)
  121. {
  122. MCI_INFO_PARMS sMCIInfo;
  123. sMCIInfo.dwCallback=0;
  124. sMCIInfo.dwRetSize=len;
  125. sMCIInfo.lpstrReturn=id;
  126. DWORD nErr= MCISendCommand(wDeviceID, MCI_INFO, MCI_INFO_MEDIA_IDENTITY, (DWORD_PTR)&sMCIInfo);
  127. return !nErr;
  128. }