我在我的应用程序运行1后台进程…它不断检查一些input…当正确的input进入发现..它会播放一些WAV文件..
我已经添加了1个wav填充名为“ding.wav”的资源..
我已经写了下面的代码在我的应用程序中…我正在使用System.Media命名空间。 并使用.Net 4.0
Soundplayer player = new Soundplayer(); player.Stream = Properties.Resources.ding; player.Play();
但声音不是在玩…
是否有可用于Windows的高可用性分布式caching选项?
如何在Windows 8.1任务pipe理器中测量磁盘的“平均响应时间”
如何以编程方式检索“Program Files”文件夹的实际path?
从Windows服务运行Windows应用程序
哪个监视器是活动的?
你能告诉我我做错了什么..!
如何使用Windows应用程序在第三方网站上填写和提交Web表单?
修整string并将其转换为小写字符的最快方法
如何使用.net TransactionScope从MQ执行事务GET?
在.net中检查等效的共享文件夹
尝试这个:
Soundplayer player = new Soundplayer(Properties.Resources.ding); player.Play();
你也可以试试这个:
using System; using System.Runtime.InteropServices; using System.Resources; using System.IO; namespace Win32 { public class Winmm { public const UInt32 SND_ASYNC = 1; public const UInt32 SND_MEMORY = 4; [DllImport("Winmm.dll")] public static extern bool PlaySound(byte[] data,IntPtr hMod,UInt32 dwFlags); public Winmm() { } public static void PlayWavResource(string wav) { // get the namespace string strNameSpace= System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString(); // get the resource into a stream Stream str = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( strNameSpace +"."+ wav ); if ( str == null ) return; // bring stream into a byte array byte[] bStr = new Byte[str.Length]; str.Read(bStr,(int)str.Length); // play the resource PlaySound(bStr,IntPtr.Zero,SND_ASYNC | SND_MEMORY); } } }
我想你必须确保文件在你播放之前被加载。
Soundplayer player = new Soundplayer(Properties.Resources.ding); player.Load(); player.Play();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。