IAudioSessionNotification,任何人都有工作代码? [英] IAudioSessionNotification, anyone have working code?

查看:308
本文介绍了IAudioSessionNotification,任何人都有工作代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在拿起一些实验代码,我现在在Windows 7测试版,我已经安装了RC。

I'm picking up some experimental code I was messing with in the Windows 7 Beta now that I've installed the RC.

基本上,我试着获取 IAudioSessionManager2 & IAudioSessionNotification 一起合作,将每个新的音讯工作阶段通知我的小应用程式。

Basically, I'm trying to get IAudioSessionManager2 & IAudioSessionNotification working together to inform my little app of every new audio session created.

Punchline代码 AudioListener (public IAudioSessionNotification ):

Punchline code in AudioListener (public IAudioSessionNotification):

//This is mostly lifted from MSDN
HRESULT STDMETHODCALLTYPE AudioListener::QueryInterface(REFIID riid, void** ppvObject)
{
    if(riid == __uuidof(IUnknown))
    {
        *ppvObject = (IUnknown*)this;
        return S_OK;
    }

    if(riid == __uuidof(IAudioSessionNotification))
    {
        *ppvObject = (IAudioSessionNotification*)this;
        return S_OK;
    }

    *ppvObject = NULL;

    return E_NOINTERFACE;
}

//m_hwnd, and WM_SESSION_CREATED are set to good values
//WM_SESSION_CREATEd via RegisterWindowMessage(...)
HRESULT STDMETHODCALLTYPE AudioListener::OnSessionCreated(IAudioSessionControl *pSession)
{
    PostMessage(m_hwnd, WM_SESSION_CREATED, (WPARAM)pSession, 0);

    return S_OK;
}

注册我的监听器的代码:

Code registering my listener:

BOOL RegisterMonitor(HWND target)
{
    BOOL success = false;

    HRESULT res;
    IMMDevice* pDevice;
    IMMDeviceEnumerator* pEnumerator;

    SESSION_LISTENER = NULL;
    SESSION = NULL;

    res = CoInitialize(NULL);

    if(res != S_OK && res != S_FALSE)
        return false;

    SESSION_LISTENER = new AudioListener(target);

    res = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
    if(res != S_OK)  goto Exit;

    res = pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
    if(res != S_OK)  goto Exit;

    res = pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&SESSION);
    if(res != S_OK)  goto Exit;

    res = SESSION->RegisterSessionNotification(SESSION_LISTENER);
    if(res != S_OK)  goto Exit;

    success = true;

Exit:
    SAFE_RELEASE(pEnumerator);
    SAFE_RELEASE(pDevice);
    if(!success)
    {
        SAFE_RELEASE(SESSION_LISTENER);
        SAFE_RELEASE(SESSION);
    }

    return success;
}

RegisterMonitor(...)返回true,但不会收到任何通知。我已经测试通过发布小的应用程序与小的声音效果和触发它们(Soltaire,扫雷器等),确认他们出现在 SndVol 当我期待看到通知。

RegisterMonitor(...) returns true, but no notifications are ever received. I've been testing by launching little apps with minor sound effects and triggering them (Soltaire, Minesweeper, etc.), confirming that they show up in SndVol when I'm expecting to see a notification.

基本上,有没有人看到我做错了?

Basically, does anyone see what I'm doing wrong?

推荐答案

您在 RegisterMonitor 函数中发布了会话管理器。一旦您释放对会话管理器的最后一个引用,它就会被释放,您将不再收到会话通知。

You released the session manager in your RegisterMonitor function. Once you release the last reference to the session manager it is freed and you'll no longer receive session notifications.

保持会话管理器对象活着,它应该工作很好。

Keep the session manager object alive and it should work just fine.

这篇关于IAudioSessionNotification,任何人都有工作代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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