我正在使用Mono为OSX10.6编写一个简单的计时器应用程序。如何播放警报声音(可以是wav / mp3文件或其他文件)?
我尝试了几种方法,但很遗憾都没有成功:
NSSound seems to be not supported by Mono yet.
MonoMac.AppKit.NSSound alarm = new MonoMac.AppKit.NSSound("alarm.wav"); alarm.Play();
Using a
SoundPlayer
didn't work either:System.Media.SoundPlayer player = new System.Media.SoundPlayer("alarm.wav"); player.PlaySync();
I was able to play a sound by opening a
System.Diagnostics.Process
and then use the OSX command line commandafplay
. Unfortunately, this command opens in a new terminal window, which is quite annoying in a GUI app.