我有windows服务,通过*.wav播放NAudio.dll文件(多线程)
public static void PlayFileBackground(string fileName)
{
Task.Run(() => { PlayFile(fileName); });
}
private static void PlayFile(string fileName)
{
if (File.Exists(fileName) == true)
{
try
{
var manualResetEvent = new ManualResetEvent(false);
using (var wfr = new WaveFileReader(fileName))
using (WaveChannel32 wc = new WaveChannel32(wfr) { Volume = 1, PadWithZeroes = false })
using (var audioOutput = new DirectSoundOut())
{
#region play
audioOutput.Init(wc);
audioOutput.Play();
audioOutput.PlaybackStopped += (sender, e) => { manualResetEvent.Set(); };
manualResetEvent.WaitOne();
audioOutput.Stop();
#endregion
}
}
catch (Exception exception)
{
logger.Error("Error NAudio.\n{0}", exception.ToString()); //<-never don't catch
}
}
}如果该区域的“play”注释为->,则所有工作
如果区域‘播放’未注释的->,有时我的服务停止,没有任何错误。
我尝试使用调试器附加:在NAudio.dll中出现了一个未处理的‘NAudio.dll’类型的异常。
另外:System.AccessViolationException类型的第一次例外发生在NAudio.dll中
有什么想法吗?
发布于 2015-03-23 08:03:11
我找到了替换DirectSoundOut > WaveOutEvent的建议。现在一切都正常了。谢谢你,斯塔德。
https://stackoverflow.com/questions/29200032
复制相似问题