声音文件folder.wav放置在bin目录下debug下
1.通过API调用
支持同步、异步播放
支持循环播放
支持文件和流播放
同步播放:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = Application.StartupPath + "\\folder.wav";
player.LoadAsync();
player.PlaySync();
循环播放
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = Application.StartupPath + "\\folder.wav";
player.Load();
player.PlayLooping();
3.使用 Audio 对象
1.通过API调用
1
using System.Runtime.InteropServices;
2
[DllImport("winmm.dll")]
3
public static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
4
public const int SND_FILENAME = 0x00020000;
5
public const int SND_ASYNC = 0x0001;
6
//调用下面的方法
7
PlaySound("folder.wav", 0, SND_ASYNC | SND_FILENAME);
8
2.通过SoundPlayer对象
2

3

4

5

6

7

8

1
using System.Media;
2
3
SoundPlayer p = new SoundPlayer();
4
p.SoundLocation = Application.StartupPath + "\\folder.wav";
5
p.Load();
6
p.Play();
SoundPlayer 
2

3

4

5

6

支持同步、异步播放
支持循环播放
支持文件和流播放
同步播放:
1
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
2
player.SoundLocation = Application.StartupPath + "\\folder.wav";
3
player.Load();
4
player.Play();
异步播放:
2

3

4

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = Application.StartupPath + "\\folder.wav";
player.LoadAsync();
player.PlaySync();
循环播放
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = Application.StartupPath + "\\folder.wav";
player.Load();
player.PlayLooping();
3.使用 Audio 对象
1
using Microsoft.VisualBasic.Devices;//Microsoft.VisualBasic.dll需要添加引用
2
3
Audio a = new Audio();
4
a.Play("folder.wav");
4.通过调用COM组件
“工具”→”自定义控件“→”COM组件“→”window mediaplay “;
然后直接在工具栏中拖拽使用

2

3

4

4.通过调用COM组件
“工具”→”自定义控件“→”COM组件“→”window mediaplay “;
然后直接在工具栏中拖拽使用