【问题标题】:WASAPI GetDisplayName returns blankWASAPI GetDisplayName 返回空白
【发布时间】:2014-11-15 16:59:36
【问题描述】:

我正在尝试编写一个与 Windows Core Audio 和 WASAPI 交互的程序。我对以下几行有困难。

CComHeapPtr<WCHAR> name;
hr = pAudioSessionControl->GetDisplayName(&name);
if (FAILED(hr)) {
    LOG(L"IAudioSessionControl::GetDisplayName() failed: hr = 0x%08x", hr);
    return -__LINE__; }
_tprintf(_T("Session Index %d, \"%s\"\n"), i, CString(name));

输出:

Session Index 0, "@%SystemRoot%\System32\AudioSrv.Dll,-202"
Session Index 1, ""
Session Index 2, ""
Session Index 3, ""
Press any key to continue . . .

这是 3 个程序都处于活动状态并发出噪音。看来我可以看到系统声音程序,但没有别的。

感谢您的帮助。

【问题讨论】:

    标签: c++ windows audio wasapi


    【解决方案1】:

    another question 的一个想法。

    问题应该与会话本身有关。大多数程序从不命名它们的会话,因此通常会话没有名称,并且混音器上显示的名称可能是会话所有者进程的窗口标题的名称。

    使用IAudioSessionControl2::GetProcessID 并通过其他API 获取进程的窗口标题应该给出一个类似于音频混合器的合理名称。

    【讨论】:

      【解决方案2】:

      IAudioSessionControl::GetDisplayName 是正确的 API,它可能会返回非空字符串,但是您也可能会看到字符串确实为空的非活动会话。在您的情况下,您可能会遇到非活动会话、您未提供的错误代码或不正确的 API 使用。

      This code snippet/application 枚举会话并轮询音量变化 - 它打印非空字符串。

      CComHeapPtr<WCHAR> pszDisplayName;
      ATLENSURE_SUCCEEDED(pSessionControl->GetDisplayName(&pszDisplayName));
      _tprintf(_T("nSessionIndex %d, pszDisplayName \"%s\"\n"), 
          nSessionIndex, CString(pszDisplayName));
      
      C:\AudioSessionVolumeNotification\Debug>AudioSessionVolumeNotification.exe
      nSessionCount 5
      nSessionIndex 0, pszDisplayName "@%SystemRoot%\System32\AudioSrv.Dll,-202"
      nSessionIndex 1, pszDisplayName "Mozilla Firefox"
      nSessionIndex 2, pszDisplayName "Mozilla Thunderbird"
      nSessionIndex 3, pszDisplayName "Mozilla Firefox"
      nSessionIndex 4, pszDisplayName ""
      

      【讨论】:

      • 感谢罗马的帮助。请参阅我的编辑以获取更多信息。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2017-11-20
      • 1970-01-01
      • 2011-05-27
      • 2012-09-06
      • 2018-11-27
      相关资源
      最近更新 更多