不在线

不在线,不常在,常常在

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::
声音文件folder.wav放置在bin目录下debug下
1.通过API调用
1using 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//调用下面的方法
7PlaySound("folder.wav"0, SND_ASYNC | SND_FILENAME);
8
2.通过SoundPlayer对象
1using System.Media;
2
3SoundPlayer p = new SoundPlayer();
4            p.SoundLocation = Application.StartupPath + "\\folder.wav";        
5            p.Load();
6            p.Play();
SoundPlayer
支持同步、异步播放
支持循环播放
支持文件和流播放
同步播放:
1System.Media.SoundPlayer player = new System.Media.SoundPlayer();
2player.SoundLocation = Application.StartupPath + "\\folder.wav";        
3player.Load();
4player.Play();
异步播放:
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 对象
1using Microsoft.VisualBasic.Devices;//Microsoft.VisualBasic.dll需要添加引用
2
3Audio a = new Audio();
4          a.Play("folder.wav");
posted on 2009-09-19 17:05  不常在  阅读(1713)  评论(2)    收藏  举报