再次播放时 NAudio 生成错误(第二次及以后)

发布于 2024-12-04 03:10:31 字数 1100 浏览 1 评论 0原文

第一次单击“播放”按钮时,一切正常,但下次它会生成此行中的错误:

    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.

Error Screenshot


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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素手挽清风 2024-12-11 03:10:32

错误代码为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文