Shaitan00 Posted July 15, 2006 Posted July 15, 2006 I am using the code below to play my background music Midi (.mid) files (for little game) and I ran into a problem I can't seem to figue out... [DllImport("winmm.dll", EntryPoint="mciSendStringA")] private static extern long mciSendString(string lpstrCommand, string lpstrReturnString, long uReturnLength, long hwndCallback); public static long PlayMidiFile(string MidiFile) { long lRet = -1; if (File.Exists(MidiFile)) { lRet = mciSendString("stop midi", "", 0, 0); lRet = mciSendString("close midi", "", 0, 0); lRet = mciSendString(("open sequencer!" + (MidiFile + " alias midi")), "", 0, 0); lRet = mciSendString("play midi", "", 0, 0); return lRet; } else { //Error Message return lRet; } } Thing is I want the Midi file to repeat/loop (it is the background music for my game, so it should play over and over again until the game ends)... So I am having 3 issues: 1- Repeat/Loop: I did some reading on MSDE and it mentions that we can use a "repeat" value, so I tried to implement it as follows (only changed this one line) but it doesn't work (the midi file never repeats) .... lRet = mciSendString("play midi", "repeat", 0, 0); Any clues? 2- And next, almost as important when my game ends it could be in the middle of playing the MIDI file - how can I STOP the play? My program remains open (incase the user decides to restart) but the background music should end at this point... There must be some way to pause/stop the playing of the midi song no? 3- The least important, is it possible to play two midi's at the same time? (one on-top of the other)? Meaning if I run [PlayMidiFile(string MidiFile)] multiple times the last run is the music I heard (they do not super-impose) but sometimes I want them to... Is this do-able with Midi using my approach? (because if I play them as WAV using my PlaySound() function it seems to work perfectly fine, they super-impose perfectly well - but as with Midi I can't super-impose two WAVs either... only by mixing the two have I been able to so far ahieve my desired results...) Any ideas, hints, and help would be greatly appreciated, thanks Quote
Administrators PlausiblyDamp Posted July 16, 2006 Administrators Posted July 16, 2006 For the repeat function try lRet = mciSendString("play midi repeat", "", 0, 0); To stop a playing track you would send the stop command using the same deviceid (midi in this case) you used to open it. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.