我先编写一个写日志的程序,希望可以在编写日志的时候程序播放出优雅的背景音乐?希望高手指点一下,谢谢!

解决方案 »

  1.   

    using System.Media;
    using System.IO;SoundPlayer music = new SoundPlayer();music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav");
    music.Play();
      

  2.   

    public class Sound 
    {
    public static void Play( string strFileName, PlaySoundFlags soundFlags) 
    {
    PlaySound( strFileName, IntPtr.Zero, soundFlags);
    // passes to Playsound the filename and a pointer
    // to the Flag
    } [DllImport("winmm.dll")] //inports the winmm.dll used for sound
    private static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
    } [Flags] //enumeration treated as a bit field or set of flags
    public enum PlaySoundFlags: int 
    { SND_SYNC = 0x0000, /* play synchronously (default) */
    SND_ASYNC = 0x0001, /* play asynchronously */
    SND_NODEFAULT = 0x0002, /* silence (!default) if sound notfound */
    SND_LOOP = 0x0008, /* loop the sound until nextsndPlaySound */
    SND_NOSTOP = 0x0010, /* don't stop any currently playingsound */
    SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
    SND_FILENAME = 0x00020000, /* name is file name */
    SND_RESOURCE = 0x00040004 /* name is resource name or atom */ 
      

  3.   

    using System.Media; 
    using System.IO; SoundPlayer music = new SoundPlayer(); music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav"); 
    music.Play();
      

  4.   

    using System.Media; private void Form1_Load(object sender, EventArgs e)
    {
        SoundPlayer msc = new SoundPlayer("文件路径");
        msc.Play();
    }
    //文件路径为音乐文件在本地磁盘的路径,后缀名为.wav。
    //例如C:\Program Files\Tencent\QQ\Misc\Sound\Classic\Audio.wav