0

I am making a game and I am trying to loop a MIDI file with mciSendString(). I have looked at CProgramming.com but the example's window objects were OWL and I couldn't port them. I also tried looking at Brian Gradin's question but the answer only contained two lines of code. I have looked on MSDN but that is like a reference and not a tutorial. Adding repeat doesn't play anything. This is the code that I have so far:

mciSendString("open PUG1.MID type sequencer alias music", NULL, 0, NULL);
mciSendString("play music", NULL, 0, NULL);

If you help then I will be sure to put you in the credits. Thank you! :)

EDIT: I have tried to handle the notify flag but my code will not work. It plays the theme once then it stops.

    //At the end of WM_CREATE...
    mciSendString("open MUSIC\\PUG2.MID type sequencer alias music", NULL, 0, NULL);
    mciSendString("play music", NULL, 0, NULL);
break;
case MM_MCINOTIFY:
    mciSendString("seek music to start", NULL, 0, NULL);
    mciSendString("play music", NULL, 0, NULL);
break;
Cœur
  • 37,241
  • 25
  • 195
  • 267
TheNoob
  • 25
  • 6
  • Have you tried `play music repeat`? – Retired Ninja Mar 25 '14 at 18:23
  • It doesn't play anything when you add it to a MIDI file. – TheNoob Mar 25 '14 at 18:28
  • Oh well, worth a try. Seems like you will have to handle it manually as suggested in the question you mentioned. The `notify` flag may be a better way to do so if it is supported with the sequencer. You might also consider a 3rd party library. – Retired Ninja Mar 25 '14 at 19:22
  • I am sorry I am bothering you but could you please post an example. My code seems to be incorrect. I will edit the topic. – TheNoob Mar 25 '14 at 21:19

1 Answers1

3

You can use the notify flag be notified when the song ends.

This seems to work:

case WM_CREATE:
    mciSendString("open pickin0.mid type sequencer alias music", NULL, 0, NULL);
    mciSendString("play music notify", NULL, 0, hWnd);
    break;

case MM_MCINOTIFY:
    mciSendString("seek music to start", NULL, 0, NULL);
    mciSendString("play music notify", NULL, 0, hWnd);
    break;

You need to pass your window handle when you use the notify command so it can send the MM_MCINOTIFY command somewhere.

Retired Ninja
  • 4,785
  • 3
  • 25
  • 35