2009-05-13 14 views
5

Sto raccogliendo un codice sperimentale con cui avevo problemi con Windows 7 Beta ora che ho installato RC.IAudioSessionNotification, qualcuno ha un codice funzionante?

Fondamentalmente, sto cercando di ottenere IAudioSessionManager2 & IAudioSessionNotification lavorare insieme per informare la mia piccola app di ogni nuova sessione audio creata.

codice Punchline in AudioListener (pubblico 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; 
} 

Codice registrare il mio ascoltatore:

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(...) restituisce vero, ma non le notifiche vengono mai ricevuti. Ho provato testando piccole app con lievi effetti sonori e attivandoli (Soltaire, Minesweeper, ecc.), Confermando che compaiono in SndVol quando mi aspetto di vedere una notifica.

Fondamentalmente, qualcuno vede cosa sto facendo male?

risposta

1

È stato rilasciato il gestore sessioni nella funzione RegisterMonitor. Una volta rilasciato l'ultimo riferimento al gestore della sessione, questo viene liberato e non riceverai più notifiche di sessione.

Mantiene vivo l'oggetto gestore sessioni e dovrebbe funzionare correttamente.

+0

Dove esattamente sono io liberando il gestore di sessione? Inoltre, anche se commento tutto il codice -> Release()/SAFE_RELEASE() (che perde oggetti COM come un setaccio) continuo a non ricevere notifiche. –

+0

Scusate, ho interpretato erroneamente la parte Exit - Non mi ero reso conto che il gestore di sessione è stato rilasciato solo nel caso di errore. –

+0

+1 che un programmatore nello stack Audio di Windows ha scritto una risposta. –

0

ho sperimentato lo stesso problema e la soluzione per me è stato quello di aggiungere una chiamata a GetSessionEnumerator() dopo la chiamata RegisterSessionNotification()

+0

Sarebbe utile se potessi aggiungere qualche breve descrizione sul motivo per cui pensi che questo potrebbe risolvere il problema. –

Problemi correlati