Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC
Article

MCI CD Player

Rate me:
Please Sign up or sign in to vote.
3.55/5 (18 votes)
23 Jan 2003 111.8K   2.8K   47   18
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Bulgaria Bulgaria
I am a senior developer in Melon Technologies Ltd.

Comments and Discussions

 
QuestionExcellent work Pin
nebojsa_j23-Apr-14 7:29
nebojsa_j23-Apr-14 7:29 
QuestionHow to eject Blank CDROM drive? Pin
reach2dpg1-Apr-06 18:11
reach2dpg1-Apr-06 18:11 
GeneralSmall Problem Pin
gpsakhare30-Sep-05 21:03
gpsakhare30-Sep-05 21:03 
AnswerRe: Small Problem [modified] Pin
reach2dpg8-Sep-06 2:05
reach2dpg8-Sep-06 2:05 
GeneralBig prolem Pin
duc_nguyen14-Feb-05 20:28
duc_nguyen14-Feb-05 20:28 
GeneralA little problem Pin
TTT8126-Jan-05 1:08
TTT8126-Jan-05 1:08 
GeneralRe: A little problem Pin
WilliamZhou25-Feb-06 23:58
WilliamZhou25-Feb-06 23:58 
Generalhi! have a error Pin
Anonymous17-Jan-05 16:05
Anonymous17-Jan-05 16:05 
GeneralNo sound while playing... Pin
Ashokkumar22-May-03 21:19
Ashokkumar22-May-03 21:19 
GeneralRe: No sound while playing... Pin
Nikolai Serdiuk26-May-03 21:26
Nikolai Serdiuk26-May-03 21:26 
GeneralRe: No sound while playing... Pin
Haiou10-Feb-06 14:00
Haiou10-Feb-06 14:00 
QuestionHow to choose the drive? Pin
Miroslav Rajcic1-Feb-03 22:07
Miroslav Rajcic1-Feb-03 22:07 
AnswerRe: How to choose the drive? Pin
ghori22-Apr-03 22:10
ghori22-Apr-03 22:10 
AnswerRe: How to choose the drive? Pin
paisano15-Jan-04 4:35
paisano15-Jan-04 4:35 
AnswerRe: How to choose the drive? Pin
m.v.d.4-Mar-06 0:55
m.v.d.4-Mar-06 0:55 
GeneralYour code is nice and neat Pin
Marc Clifton24-Jan-03 10:22
mvaMarc Clifton24-Jan-03 10:22 
Generalhmm... Pin
Nitron24-Jan-03 9:48
Nitron24-Jan-03 9:48 
GeneralRe: hmm... Pin
Lito28-Jan-03 14:18
Lito28-Jan-03 14:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.