NAudio WasapiLoopbackCapture ComException(0x88890003) [英] NAudio WasapiLoopbackCapture ComException (0x88890003)

查看:557
本文介绍了NAudio WasapiLoopbackCapture ComException(0x88890003)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用WasapiLoopbackCapture类(NAudio 1.7.1.17),并以COMException(0x88890003)结尾.记录格式为WaveFormat(44100, 16, 2).我的系统上有多个播放设备,并尝试将每个播放设备设置为默认设备,结果相同.我还验证了每个设备都将(44100, 16, 2)列为受支持的格式.

I am trying to use the WasapiLoopbackCapture class (NAudio 1.7.1.17) and ending up with the COMException (0x88890003). The recording format is WaveFormat(44100, 16, 2). I have multiple playback devices on my system and have tried setting each one as the default device with the same results. I have also verified that each of those devices has (44100, 16, 2) listed as a supported format.

控制台输出:

WasapiCapture_RecordingStopped.

Exception: System.Runtime.InteropServices.COMException (0x88890003): Exception from HRESULT: 0x88890003
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at NAudio.CoreAudioApi.AudioClient.get_AudioCaptureClient()
   at NAudio.CoreAudioApi.WasapiCapture.DoRecording(AudioClient client)
   at NAudio.CoreAudioApi.WasapiCapture.CaptureThread(AudioClient client)

代码:

public static class Program
{
    private static int Index = 0;
    private static int TotalBytesRecorded = 0;
    private static bool RecordingStopped = false;

    private static void Main (string [] args)
    {
        var device = NAudio.Wave.WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice();

        using (var capture = new NAudio.CoreAudioApi.WasapiCapture(device))
        {
            capture.WaveFormat = new NAudio.Wave.WaveFormat(44100, 16, 2);
            capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
            capture.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(Program.WasapiCapture_DataAvailable);
            capture.RecordingStopped += new EventHandler<NAudio.Wave.StoppedEventArgs>(Program.WasapiCapture_RecordingStopped);

            Program.Index = 0;
            Program.TotalBytesRecorded = 0;
            Program.RecordingStopped = false;

            capture.StartRecording();
            Thread.Sleep(TimeSpan.FromSeconds(10));
            capture.StopRecording();

            while (!Program.RecordingStopped)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(10));
            }
        }

        Console.WriteLine();
        Console.WriteLine();
        Console.Write("TotalBytesRecorded: {0}.", Program.TotalBytesRecorded.ToString("N0"));
    }

    private static void WasapiCapture_DataAvailable (object sender, NAudio.Wave.WaveInEventArgs e)
    {
        Program.Index++;
        Program.TotalBytesRecorded += e.BytesRecorded;

        Console.WriteLine();
        Console.Write
        (
            "Index: {0}, BytesRecorded: {1}, Buffer Length: {2}, TotalBytesRecorded: {3}.",
            Program.Index.ToString("N0").PadLeft(10, ' '),
            e.BytesRecorded.ToString("N0").PadLeft(10, ' '),
            e.Buffer.Length.ToString("N0").PadLeft(10, ' '),
            Program.TotalBytesRecorded.ToString("N0").PadLeft(10, ' ')
        );
    }

    private static void WasapiCapture_RecordingStopped (object sender, NAudio.Wave.StoppedEventArgs e)
    {
        Program.RecordingStopped = true;

        Console.WriteLine();
        Console.WriteLine();
        Console.Write("WasapiCapture_RecordingStopped.");

        if (e.Exception != null)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.Write("Exception: {0}", e.Exception);
        }
    }
}

任何提示将不胜感激.

推荐答案

您无法为WASAPI回送捕获设置捕获-必须使用系统混合格式,该格式将使用32位浮点样本.只需直接使用WasapiLoopbackCapture类,它将起作用.

You can't set the capture for WASAPI loopback capture - you have to use the system mix format, which will use 32 bit floating point samples. Just use the WasapiLoopbackCapture class directly and it will work.

这篇关于NAudio WasapiLoopbackCapture ComException(0x88890003)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆