不在线

不在线,不常在,常常在

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::
  33 随笔 :: 1 文章 :: 244 评论 :: 17727 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
声音文件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   不常在  阅读(1694)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示