65.9K
CodeProject is changing. Read more.
Home

MCI CD Player

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.55/5 (18 votes)

Jan 24, 2003

viewsIcon

113363

downloadIcon

2801

An article about Media Control Interface (MCI)

Sample Image - cdplayer.png

Introduction

This project explores the Microsoft Media Control Interface (MCI). I wrote a wrapper for MCI CD Audio commands. The class wrapper was named CCDAudio.

Details

The CCDAudio class declaration is:

//========================================================================
// A class wrapper of MCI API functions
//========================================================================
class CCDAudio
{
public:
// constructor
CCDAudio();
// destructor
virtual ~CCDAudio();

// Start playing CD Audio
MCIERROR Play();
// Start playing CD Audio on given position
MCIERROR Play(const int nPos);
// Stop playing CD Audio
MCIERROR Stop();
// Pause playing CD Audio
MCIERROR Pause();
// Move to the next track
MCIERROR Forward();
// Move to the previous track
MCIERROR Backward();
// Eject the CDROM
void EjectCDROM();

// Return the current position in seconds
int GetCurrentPos();
// Return the current track number
int GetCurrentTrack();
// Return length of all track in seconds
int GetLenghtAllTracks();
// Return total tracks count
int GetTracksCount();
// Return length of given track
int GetTrackLength(const int nTrack);
// Return begin time of given track
int GetTrackBeginTime( const int nTrack );

// check wheter CD media is inserted
bool IsMediaInsert();
// is paused mode
bool IsPaused();
// is stopped mode
bool IsStopped();
// the device is ready
bool IsReady();
// is playing mode
bool IsPlaying();

protected:
    // MCI error code
    MCIERROR m_nErrorCode;

protected:
    // handle MCI errors
    inline void MCIError( MCIERROR MCIError );
};
All of the functions are divided into three groups:
  1. Manage functions.
  2. Time and position functions.
  3. Status functions.
Note: The time is represented in seconds.

Use of CCDAudio

  1. First you should create an instance of this class:
    protected:
        CCDAudio m_CDAudio;
    
  2. For starting to play the tracks:
    m_CDAudio.Play();
    
  3. To pause playing:
    m_CDAudio.Pause();
    
  4. To stop playing:
    m_CDAudio.Stop();
    
  5. Move to the previous track:
    m_CDAudio.Backward();
  6. Move to the next track:
    m_CDAudio.Forward();
  7. Eject/Close CD ROM:
    m_CDAudio.EjectCDROM();
  8. Play from begining of the selected track:
    m_CDAudio.Play( m_CDAudio.GetTrackBeginTime( nTrack ) );

That is all. I hope this class will be useful.