首页  编辑  

播放声音

Tags: /C#/多媒体/   Date Created:

using System . Runtime . InteropServices;

public static uint SND_ASYNC = 0x0001 ;   // play asynchronously

[ DllImport ( "winmm.dll" )]

public static extern bool sndPlaySound( string lpszSoundName, uint fuSound);    

       

private void button4_Click( object sender, EventArgs e)

{

       sndPlaySound( "chord" , SND_ASYNC);

}

// or

using System . Media;

private void button1_Click( object sender , EventArgs e)

{

    //

    SoundPlayer sndPing = new SoundPlayer ();

   sndPing . Stream = Properties . Resources . MySound;

   sndPing . Play();

    //

    SoundPlayer vSoundPlayer = new SoundPlayer ();

   vSoundPlayer . Stream = new FileStream ( @"C:\WINDOWS\Media\chord.wav" ,

        FileMode . Open, FileAccess . Read);

   vSoundPlayer . Play();

}