Now I am working on a simple C # software. In order to beautify and multimedia things, I need to play music when the form is started. I found this on msdn and recorded it for later use!
Source code:
Using system;
Using system. runtime. interopservices;
Namespace GIS
{
/// <Summary>
/// Summary of cmedia.
/// </Summary>
Internal class csoundplay
{
Public csoundplay ()
{
//
// Todo: add the constructor logic here
//
}
[Flags]
Public Enum playsoundflags: int
{
Snd_sync = 0x0000,/* play synchronously (default )*/
Snd_async = 0x0001,/* Play asynchronously */
Snd_nodefault = 0x0002,/* silence (! Default) if sound not found */
Snd_memory = 0x0004,/* pszsound points to a memory file */
Snd_loop = 0x0008,/* loop the sound until next sndplaysound */
Snd_nostop = 0x0010,/* don't stop any currently playing sound */
Snd_nowait = 0x00002000,/* Don't wait if the driver is busy */
Snd_alias = 0x00010000,/* name is a registry alias */
Snd_alias_id = 0x00110000,/* alias is a predefined ID */
Snd_filename = 0x00020000,/* name is file name */
Snd_resource = 0x00040004/* Name Is Resource Name or atom */
}
[Dllimport ("winmm. dll")]
Public static extern bool playsound (string szsound, intptr hmod, playsoundflags flags );
}
Public class sound
{
Public static void play (string strfilename)
{
Csoundplay. playsound (strfilename, intptr. Zero, csoundplay. playsoundflags. snd_filename | csoundplay. playsoundflags. snd_async );
}
}
}
1. Add the above Code to your project;
2. Call: Sound. Play (soundfilepathandname );
Note: This method must ensure that the winmm. dll file is available on your machine. What is the role of this file! You can query it online!
Usage: