audio - no sound heard while playing a MIDI file in C#.Net -


i use code play midi file game, can not hear sound speakers. me? it's kind of emergency, please... speakers turned on ;)

[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;  } } 

i not sure implementation of winmm.dll have tested , working code it.

i got source code open source project: tea timer.

the implementation of code pretty straight forward below. hope helps.

using system; using system.text; using system.runtime.interopservices; using system.io;  namespace teatimer {     /// <summary>     /// mciplayer based off code slain.     /// found here: http://www.sadeveloper.net/articles_view.aspx?articleid=212     /// </summary>     public class mciplayer     {         private static readonly string salias="teatimeraudio";          [dllimport("winmm.dll")]         private static extern long mcisendstring(string strcommand,stringbuilder strreturn,int ireturnlength, intptr hwndcallback);         [dllimport("winmm.dll")]         private static extern long playsound(byte[] data, intptr hmod, uint32 dwflags);          public static void play(string sfile)         {             _open(sfile);             _play();         }         public static void stop()          {             _close();         }          private static void _open(string sfilename)         {             if(_status()!="")                 _close();              string scommand = "open \"" + sfilename + "\" alias "+salias;             mcisendstring(scommand, null, 0, intptr.zero);         }          private static void _close()         {             string scommand = "close "+salias;             mcisendstring(scommand, null, 0, intptr.zero);         }          private static void _play()         {             string scommand = "play "+salias;             mcisendstring(scommand, null, 0, intptr.zero);         }          private static string _status()         {             stringbuilder sbuffer = new stringbuilder(128);             mcisendstring("status "+salias+" mode", sbuffer, sbuffer.capacity, intptr.zero);             return sbuffer.tostring();         }     } } 

edit: how play , stop music file:

public static void playsound(string sfile)  {     //wavplay.wavplayer.play(sfile);     mciplayer.play(sfile); } public static void stopsound()  {     //wavplay.wavplayer.stopplay();     mciplayer.stop(); } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -