Step 5: Playing the MIDI File

Now that all of the preparatory work has been done, playing the music is simplicity itself.

IDirectMusicSegmentState* g_pSegState;
if (g_pMIdiSEG)
{
    g_pPerf->PlaySegment(g_pMIDISeg, 0, 0, &g_pSegState);
}
 

The call to IDirectMusicPerformance::PlaySegment takes the following parameters:

If you want the file to be played more than once, before calling PlaySegment you must call the IDirectMusicSegment::SetRepeats method.

If you want to stop the music before it has played to the end or finished its repeats, you do so by using the IDirectMusicPerformance::Stop method. The simplest way to use this method is simply to request that all music currently playing or cued to play be stopped immediately:

g_pPerf->Stop(NULL, NULL, 0, 0)
 

Alternatively, you can supply a pointer to the current segment or segment state in order to stop playback of just one segment, or one instance of that segment.