再次播放时 NAudio 生成错误(第二次及以后)
第一次单击“播放”按钮时,一切正常,但下次它会生成此行中的错误:
waveOutDevice.Init(mainOutputStream);
请参阅屏幕截图以了解错误的详细信息。下面是我的代码部分:
private void Play()
{
string audioFile = "temp.mp3";
try
{
if (mainOutputStream != null)
mainOutputStream = null;
mainOutputStream = CreateInputStream(audioFile);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
if (mainOutputStream != null)
{
waveOutDevice.Init(mainOutputStream);
waveOutDevice.Play();
}
else
{
return;
}
}
错误代码是:-2004287486
TargetSite 是:{Void ThrowExceptionForHRInternal(Int32, IntPtr)}
所有这些都超出了我的范围,所以请帮我指出错误站点并有一些解释(如果可能的话),当然还有针对这种情况的解决方法。谢谢。
更新:
感谢您的回复。也尝试过,但仍然是同样的问题。该文件将再次播放,但该错误消息在延迟一段时间后仍然出现。有时,错误消息会在整个应用程序关闭后几秒钟出现。而且它会出现很多次,一次又一次,可能每次播放文件时都会出现一次。
The first time I click the PLAY button, everything works fine, but the next time it generates the error in this line :
waveOutDevice.Init(mainOutputStream);
Please see the screenshot for details of the error. Here below is the section of my code :
private void Play()
{
string audioFile = "temp.mp3";
try
{
if (mainOutputStream != null)
mainOutputStream = null;
mainOutputStream = CreateInputStream(audioFile);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
if (mainOutputStream != null)
{
waveOutDevice.Init(mainOutputStream);
waveOutDevice.Play();
}
else
{
return;
}
}
The error code is : -2004287486
TargetSite is : {Void ThrowExceptionForHRInternal(Int32, IntPtr)}
All this is going over my head, so please help me point out the error site and with a little bit of explanation(if possible) and of course a work around for this situation. Thanks.
UPDATE:
Thanks for the response. Tried that as well, but still the same problem. The file gets played again, but that error message keeps appearing after some delay. Sometimes, the error-message appears few seconds after the entire application has been closed. And it appears a lot of times, one-after-another, probably once for every time the file was played.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误代码为 0x88890002 (AUDCLNT_E_ALREADY_INITIALIZED ),这表明旧的输出设备没有得到正确处理。确保您处置了您的 waveOutDevice 并为下一次播放创建一个新设备。
The error code is 0x88890002 (AUDCLNT_E_ALREADY_INITIALIZED), which points to the old output device not being disposed properly. Make sure you Dispose of your waveOutDevice and create a new one for the next playback.