共用方式為


(audiopolicy.h) IAudioSessionNotification 介面

IAudioSessionNotification 介面會在建立音訊會話時提供通知。

繼承

IAudioSessionNotification 介面繼承自 IUnknown 介面。 IAudioSessionNotification 也有下列類型的成員:

方法

IAudioSessionNotification 介面具有這些方法。

 
IAudioSessionNotification::OnSessionCreated

OnSessionCreated 方法會通知已註冊的進程已建立音訊會話。

備註

不同於 WASAPI 系統元件所實作的其他 WASAPI 介面, IAudioSessionNotification 介面是由應用程式實作。 若要接收事件通知,應用程式會傳遞至 IAudioSessionManager2::RegisterSessionNotification 方法的指標,指向其 IAudioSessionNotification 實作 。

註冊其 IAudioSessionNotification 介面之後,應用程式會透過 介面中的方法,以回呼的形式接收事件通知。

當應用程式不再需要接收通知時,它會呼叫 IAudioSessionManager2::UnregisterSessionNotification 方法。 這個方法會移除應用程式先前註冊的 IAudioSessionNotification 介面註冊。

應用程式不得在事件回呼期間註冊或取消註冊通知回呼。

會話列舉值可能不知道透過 IAudioSessionNotification 報告的新會話。 因此,如果應用程式只依賴會話列舉值來取得音訊端點的所有會話,結果可能不正確。 若要解決此問題,應用程式應該手動維護清單。 如需詳細資訊,請參閱 IAudioSessionEnumerator

注意 在非UI線程中呼叫 CoInitializeEx(NULL, COINIT_MULTITHREADED) ,確定應用程式使用多線程Apartment (MTA) 模型初始化 COM。 如果未初始化 MTA,應用程式就不會從會話管理員接收工作階段通知。 執行應用程式使用者介面的線程應該初始化 Apartment 線程模型。
 

範例

下列程式代碼範例示範 IAudioSessionNotification 介面的範例實作。

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);
        }
    }
};

規格需求

需求
最低支援的用戶端 Windows 7 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 R2 [僅限桌面應用程式]
目標平台 Windows
標頭 audiopolicy.h

另請參閱

核心音訊介面