I need some code help for playing a MIDI file without interupting the actual program, it would play in the background, also it needs to have a pause button.
Printable View
I need some code help for playing a MIDI file without interupting the actual program, it would play in the background, also it needs to have a pause button.
Use the mciSendString API. In the following example, you will need to make a series of CommandButton. It might be a good idea to change the caption to the correct function.
code for module.
Put this code in a CommandButtonCode:Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Put this in another CommandButtonCode:'Opens the file
mciSendString "open C:\MyMIDI.mid type sequencer alias background", 0, 0, 0
Put this code in another CommandButtonCode:' Plays the midi
mciSendString "play background", 0, 0, 0
Put this code in another CommandButtonCode:'Pauses the midi
mciSendString "pause background", 0, 0, 0
Code:'Closes the file
mciSendString "close background", 0, 0, 0
Always make sure that you Close the file before exiting the program because it will contiune to play until Windows sends a message for the program to stop. This means that if you exit your App while the music is playing, it will still contiune to play. So to prevent this, aslways close the file when you are done.