IAudioSessionNotification interface

The IAudioSessionNotification interface provides notification when an audio session is created.

Members

The IAudioSessionNotification interface inherits from the IUnknown interface. IAudioSessionNotification also has these types of members:

Methods

The IAudioSessionNotification interface has these methods.

MethodDescription
OnSessionCreated

Notifies the registered processes that the audio session has been created.

 

Remarks

Unlike the other WASAPI interfaces, which are implemented by the WASAPI system component, the IAudioSessionNotification interface is implemented by the application. To receive event notifications, the application passes to the IAudioSessionManager2::RegisterSessionNotification method a pointer to its IAudioSessionNotification implementation .

After registering its IAudioSessionNotification interface, the application receives event notifications in the form of callbacks through the methods in the interface.

When the application no longer needs to receive notifications, it calls the IAudioSessionManager2::UnregisterSessionNotification method. This method removes the registration of an IAudioSessionNotification interface that the application previously registered.

The application must not register or unregister notification callbacks during an event callback.

The session enumerator might not be aware of the new sessions that are reported through IAudioSessionNotification. So if an application exclusively relies on the session enumerator for getting all the sessions for an audio endpoint, the results might not be accurate. To work around this, the application should manually maintain a list. For more information, see IAudioSessionEnumerator.

Note  Make sure that the application initializes COM with Multithreaded Apartment (MTA) model by calling CoInitializeEx(NULL, COINIT_MULTITHREADED) in a non-UI thread. If MTA is not initialized, the application does not receive session notifications from the session manager. Threads that run the user interface of an application should be initialized apartment threading model.

Examples

The following code example shows a sample implementation of the IAudioSessionNotification interface.


class CSessionNotifications: public IAudioSessionNotification
{
private:

    LONG             m_cRefAll;
    HWND m_hwndMain;

    ~CSessionManager(){};

public:


    CSessionManager(HWND hWnd): 
    m_cRefAll(1),
    m_hwndMain (hWnd)

    {}

    // IUnknown
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppv)  
    {    
        if (IID_IUnknown == riid)
        {
            AddRef();
            *ppvInterface = (IUnknown*)this;
        }
        else if (__uuidof(IAudioSessionNotification) == riid)
        {
            AddRef();
            *ppvInterface = (IAudioSessionNotification*)this;
        }
        else
        {
            *ppvInterface = NULL;
            return E_NOINTERFACE;
        }
        return S_OK;
    }
    
    ULONG STDMETHODCALLTYPE AddRef()
    {
        return InterlockedIncrement(&m_cRefAll);
    }
     
    ULONG STDMETHODCALLTYPE Release)()
    {
        ULONG ulRef = InterlockedDecrement(&m_cRefAll);
        if (0 == ulRef)
        {
            delete this;
        }
        return ulRef;
    }

    HRESULT OnSessionCreated(IAudioSessionControl *pNewSession)
    {
        if (pNewSession)
        {
            PostMessage(m_hwndMain, WM_SESSION_CREATED, 0, 0);
        }
    }
};

Requirements

Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]

Header

Audiopolicy.h

See also

Core Audio Interfaces

 

 

Community Additions

ADD
Show:
© 2014 Microsoft