Condividi tramite


Interfaccia IAudioEffectsChangedNotificationClient (audioclient.h)

Un'interfaccia di callback consente alle applicazioni di ricevere notifiche quando l'elenco di effetti audio per il flusso audio associato cambia o quando le risorse necessarie per abilitare le modifiche di un effetto, ad esempio quando il valore del campo canSetState del AUDIO_EFFECT associato cambia.

Ereditarietà

L'interfaccia IAudioEffectsChangedNotificationClient eredita dall'interfaccia IUnknown.

Metodi

L'interfaccia IAudioEffectsChangedNotificationClient include questi metodi.

 
IAudioEffectsChangedNotificationClient::OnAudioEffectsChanged

Chiamato dal sistema quando l'elenco degli effetti audio cambia o le risorse necessarie per abilitare le modifiche di un effetto.

Commenti

Registrare l'interfaccia di callback chiamando IAudioEffectsManager::RegisterAudioEffectsChangedNotificationCallback.

Esempio

L'esempio di codice seguente illustra una classe che implementa IAudioEffectsChangedNotificationClient per ricevere notifiche quando l'elenco di effetti audio cambia o le risorse necessarie per abilitare le modifiche di un effetto. Nel callback OnAudioStreamEffectsChanged , l'esempio chiama GetAudioEffects per ottenere l'elenco corrente di effetti.

class AudioEffectsChangedHandler :
    public winrt::implements<AudioEffectsChangedHandler, IAudioEffectsChangedNotificationClient>
{

    public:
    AudioEffectsChangedHandler(_In_ IAudioClient *client) : m_client(client){}
    STDMETHOD(OnAudioEffectsChanged)()
    {
        OnAudioStreamEffectsChanged(m_client.get());
        return S_OK;
    }
    private:
    wil::com_ptr_nothrow<IAudioClient> m_client;

};

wil::com_ptr_nothrow<IAudioEffectsChangedNotificationClient> g_effectsChangedHandler;

HRESULT RegisterAudioStreamEffectsChangedEvent(_In_ IAudioClient *client)
{
    if (!g_effectsChangedHandler)
    {
        wil::com_ptr_nothrow<IAudioEffectsManager> audioEffectsManager;
        RETURN_IF_FAILED(client->GetService(IID_PPV_ARGS(&audioEffectsManager)));

        // Register for the audio effects changed notification
        g_effectsChangedHandler = winrt::make<AudioEffectsChangedHandler>(client).get();
        RETURN_IF_NULL_ALLOC(g_effectsChangedHandler);

        return audioEffectsManager->RegisterAudioEffectsChangedNotificationCallback(
            g_effectsChangedHandler.get());
    }
    return S_OK;
}

HRESULT UnregisterAudioStreamEffectsChangedEvent(_In_ IAudioClient *client)
{
    if (g_effectsChangedHandler != nullptr)
    {
        wil::com_ptr_nothrow<IAudioEffectsManager> audioEffectsManager;
        RETURN_IF_FAILED(client->GetService(IID_PPV_ARGS(&audioEffectsManager)));

        // Unregister from the audio effects changed notification 
        return audioEffectsManager->UnregisterAudioEffectsChangedNotificationCallback(
            g_effectsChangedHandler.get());
        }

        return S_OK;
}

HRESULT OnAudioStreamEffectsChanged(_In_ IAudioClient *client)
{
    // Re-query the list of effects since there was some change
    wil::com_ptr_nothrow<IAudioEffectsManager> audioEffectsManager;
    RETURN_IF_FAILED(client->GetService(IID_PPV_ARGS(&audioEffectsManager)));
    wil::unique_cotaskmem_array_ptr<AUDIO_EFFECT> effects;
    UINT32 numEffects;
    RETURN_IF_FAILED(audioEffectsManager->GetAudioEffects(&effects, &numEffects));

    for (UINT32 i = 0; i < numEffects; i++)
    {

        // Here the app can check which effects are still enabled, and check if there are new
        // effects that now can be enabled.
        // As an example, the following code enables any effect that can be enabled, if it is not
        // already enabled.
        if (effects[i].canSetState && effects[i].state == AUDIO_EFFECT_STATE_OFF)
        {
            HRESULT hr = audioEffectsManager->SetAudioEffectState(effects[i].id, AUDIO_EFFECT_STATE_ON));
            if (hr == AUDCLNT_E_EFFECT_NOT_AVAILABLE || hr == AUDCLNT_E_EFFECT_STATE_READ_ONLY)
            {
                hr = S_OK;
            }
            RETURN_IF_FAILED(hr);

        }
    }

    return S_OK;
}

Requisiti

Requisito Valore
Client minimo supportato Windows Build 22000
Intestazione audioclient.h

Vedi anche

AUDIO_EFFECT

IAudioEffectsManager::RegisterAudioEffectsChangedNotificationCallback