[Message Deleted]
-
Depends, have you stepped through it ? Might your midi settings be off ? I know I have a program that uses MIDI, but it doesn't play anything, I can't work out what is wrong with my MIDI settings.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
Your code plays fine for me. What OS are you using? You may need to set the correct MIDIOut device in the Sound section in Control Panel. If it's Vista or Weven, it's not there so use my MIDI out setter[^] if needed. Check the volume(s) in your mixer. I belive from the docs (not tested), to loop, you'll need to get notification that it's finished and start it again. You do this by adding " notify" to your command and sending a pointer (could be a hwnd) or a delegate (function pointer) as the last parameter. I think the message you need is MM_MCINOTIFY (0x3B9).
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
I've created a new boilerplate project, pasted and ammended your code. This works - and loops:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}void Form1\_Shown(object sender, EventArgs e) { DoPlay(); } private const int MM\_MCINOTIFY = 0x3B9; \[DllImport("winmm.dll")\] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, IntPtr hwndCallback); public bool PlayMidiFile(string midiFile) { if (File.Exists(midiFile)) { mciSendString("stop midi", string.Empty, 0, IntPtr.Zero); mciSendString("close midi", string.Empty, 0, IntPtr.Zero); mciSendString("open sequencer!" + midiFile + " alias midi", string.Empty, 0, IntPtr.Zero); int rtn = mciSendString("play midi notify", string.Empty, 0, this.Handle); return (rtn == 0); } else return false; } void DoPlay() { PlayMidiFile(@"C:\\Windows\\Media\\town.mid"); } protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == MM\_MCINOTIFY) DoPlay(); } }
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)