Logged in as Guest   Fri, Mar. 26th, 4:19 AM.      
Visitor Map
Recent Entries:
My Dev Setup Lately
Three Ways To Randomize on the iPhone
How to Remove .svn Directories On a Mac
How To Detect The iPhone Simulator
iPhoneMom Likes Doodle Games!
Updates To the Doodle Games Line
Three Jacks Now Tweets
Second iPhone App Submitted For Approval!
Pinch Media Analytics for iPhone
New iPhone Game Coming Soon!

Archive:
January - 2010
November - 2009
October - 2009
September - 2009
August - 2009
July - 2009
June - 2009
April - 2009
March - 2009
January - 2009
May - 2008
April - 2008
March - 2008
October - 2007
August - 2007
July - 2007
June - 2007
May - 2007
April - 2007
December - 2006
November - 2006
September - 2006
August - 2006
July - 2006
March - 2006
February - 2006
January - 2006
December - 2005
November - 2005
October - 2005
September - 2005
August - 2005
July - 2005
June - 2005
May - 2005
April - 2005
February - 2005
January - 2005
December - 2004
November - 2004
October - 2004
September - 2004
August - 2004
July - 2004
June - 2004
May - 2004
April - 2004
March - 2004
MCI CD Control
This is the MCI control code that I wrote for my UglyCD player. It is fairly full featured, but if you need more, feel free to modify it to your needs. I have neglected the error checking code, and every call to mciSendCommand should really be checked for its return value. As usual, this code is usable at your own risk. If you have any questions, you are always free to ask.

-BossHogg

#ifndef MCI_CONTROL
#define MCI_CONTROL 1

class MCIControl
{
     public:
          MCIControl();
          ~MCIControl();

          int     GetNumberOfTracks();
          void    Resume();
          void    Pause();
          void    Play();
          void    Stop();
          void    OpenDoor();
          void    CloseDoor();

          void    Goto(int track,int minute, int second);
		
          int     GetCurrentTrack();
          int     GetCurrentMinute();
          int     GetCurrentSecond();

     protected:
          void    Init();
          void    SetTimeFormat();
          void    GetPosition(BYTE* track,BYTE* min,BYTE* sec);

     private:
          MCIDEVICEID   itsMCIDevice;
};

#endif




#include "windows.h"
#include "MCIControl.h"

MCIControl::MCIControl() :
itsMCIDevice(0)
{
Init();
SetTimeFormat();
}

MCIControl::~MCIControl()
{
MCI_GENERIC_PARMS Info;

Info.dwCallback=0;
mciSendCommand(itsMCIDevice, MCI_CLOSE, MCI_NOTIFY, DWORD(&Info));
}

void MCIControl::Resume()
{
MCI_PLAY_PARMS Info;
BYTE track,minute,second;

GetPosition(&track,&minute,&second);
Info.dwTo=0;
Info.dwCallback=0;
Info.dwFrom = MCI_MAKE_TMSF(track,minute,second,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info));
}

void MCIControl::Pause()
{
MCI_GENERIC_PARMS Info;

Info.dwCallback = 0;
mciSendCommand(itsMCIDevice, MCI_PAUSE, MCI_NOTIFY, DWORD(&Info));
}

void MCIControl::Goto(int track,int minute, int second)
{
MCI_PLAY_PARMS Info;
Info.dwCallback=0;
Info.dwTo=0;
Info.dwFrom = MCI_MAKE_TMSF(track,minute,second,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info));
}


void MCIControl::Play()
{
MCI_PLAY_PARMS Info;
Info.dwCallback=0;
Info.dwTo=0;
Info.dwFrom = MCI_MAKE_TMSF(0,0,0,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info));
}

void MCIControl::Stop()
{
MCI_GENERIC_PARMS Info;
Info.dwCallback = 0;
mciSendCommand(itsMCIDevice, MCI_STOP, MCI_NOTIFY, DWORD(&Info));
}

void MCIControl::OpenDoor()
{
MCI_STATUS_PARMS Info;
Info.dwCallback=0;
Info.dwItem=0;
Info.dwReturn=0;
Info.dwTrack=0;
mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_DOOR_OPEN, DWORD(&Info));
}

void MCIControl::CloseDoor()
{
MCI_STATUS_PARMS Info;
Info.dwCallback=0;
Info.dwItem=0;
Info.dwReturn=0;
Info.dwTrack=0;
mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_DOOR_CLOSED, DWORD(&Info));
}

int MCIControl::GetCurrentTrack()
{
BYTE track;
GetPosition(&track,NULL,NULL);
return track;
}

int MCIControl::GetCurrentMinute()
{
BYTE minute;
GetPosition(NULL,&minute,NULL);
return minute;
}

int MCIControl::GetCurrentSecond()
{
BYTE second;
GetPosition(NULL,NULL,&second);
return second;
}

int MCIControl::GetNumberOfTracks()
{
MCI_STATUS_PARMS Info;
Info.dwCallback = 0;
Info.dwReturn = 0;
Info.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
Info.dwTrack = 0;
mciSendCommand(itsMCIDevice,MCI_STATUS,MCI_STATUS_ITEM,DWORD(&Info));

return (int)Info.dwReturn;
}

void MCIControl::GetPosition(BYTE* track,BYTE* min,BYTE* sec)
{
MCI_STATUS_PARMS Info;
DWORD MSF;

Info.dwCallback=0;
Info.dwReturn=0;
Info.dwTrack=0;
Info.dwItem = MCI_STATUS_POSITION;
mciSendCommand(itsMCIDevice, MCI_STATUS, MCI_STATUS_ITEM, DWORD(&Info));

MSF = Info.dwReturn;

if (track)
*track = MCI_MSF_MINUTE(MSF);
if (min)
*min = MCI_MSF_SECOND(MSF);
if (sec)
*sec = MCI_MSF_FRAME(MSF);
}

void MCIControl::SetTimeFormat()
{
MCI_SET_PARMS Info;
Info.dwCallback=0;
Info.dwTimeFormat=MCI_FORMAT_TMSF;
Info.dwAudio=0;

mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_TIME_FORMAT, DWORD(&Info));
}

void MCIControl::Init()
{
MCI_OPEN_PARMS Info;

Info.dwCallback=0;
Info.lpstrAlias=0;
Info.lpstrElementName=0;
Info.wDeviceID=0;
Info.lpstrDeviceType=MAKEINTRESOURCE(MCI_DEVTYPE_CD_AUDIO);
mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID, DWORD(&Info));

itsMCIDevice = Info.wDeviceID;
}