> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Método IAudioStateMonitor::GetSoundLevel

> Método IAudioStateMonitor::GetSoundLevel

# Método IAudioStateMonitor::GetSoundLevel

\[Algumas informações estão relacionadas a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento comercial. A Microsoft não oferece garantias, expressas ou implícitas, com relação às informações fornecidas aqui.]

Obtém o nível de som atual dos fluxos associados a [IAudioStateMonitor](/pt-BR/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor).

## Sintaxe

```cpp theme={null}
AudioStateMonitorSoundLevel GetSoundLevel();
```

### Parâmetros

Este método não tem parâmetros.

### Valor de retorno

Um valor da enumeração [AudioStateMonitorSoundLevel](/pt-BR/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel) que indica o nível de som atual dos fluxos associados ao [IAudioStateMonitor](/pt-BR/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor).

## Comentários

Considere o cenário a seguir, em que um jogo opta por reproduzir áudio GameMedia somente quando se sabe que o áudio não será silenciado pelo sistema operacional devido a uma política. Para conseguir isso, o jogo se registra para receber notificações de SoundLevel para a categoria de fluxo [AudioCategory\_GameMedia](https://learn.microsoft.com/windows/desktop/api/audiosessiontypes/ne-audiosessiontypes-audio_stream_category) no ponto de extremidade de console padrão. Se o SoundLevel dessa categoria estiver definido como 'Muted', o jogo interromperá a reprodução do fluxo GameMedia. Se o SoundLevel estiver definido como qualquer outro valor, o jogo optará por reproduzir o fluxo GameMedia.

```cpp theme={null}
// global variables 
winrt::com_ptr<IAudioStateMonitor> g_audioStateMonitor; 
AudioStateMonitorRegistrationHandle g_registration = 0; 

// Returns true if the GameMedia stream should be disabled, false if it should be 
// enabled. 
bool IsSoundLevelMuted(_In_ IAudioStateMonitor* audioStateMonitor) 
{ 
    return (audioStateMonitor->GetSoundLevel() == AudioStateMonitorSoundLevel::Muted); 
} 

HRESULT StartTrackingSoundLevel() 
{ 
    // Create an AudioStateMonitor and register for callbacks from it. 
    HRESULT hr = RegisterForSoundLevelChanges(); 
    if (SUCCEEDED(hr)) 
    { 
        // Check the current sound level and determine if the GameMedia stream should 
        // be enabled. 
        bool disableGameMediaStream = IsSoundLevelMuted(g_audioStateMonitor.get()); 

        // Add code here that enables or disables the GameMedia stream based on the 
        // value of the boolean. 
    } 
    return hr; 
} 

HRESULT RegisterForSoundLevelChanges() 
{ 
    HRESULT hr = S_OK; 

    // Create a new AudioStateMonitor for the GameMedia category, if needed, and 
    // register for callbacks. 
    if (m_audioStateMonitor == nullptr) 
    { 
        hr = CreateRenderAudioStateMonitorForCategoryAndDeviceRole( 
            AudioCategory_GameMedia, ERole::eConsole, g_audioStateMonitor.put()); 
        if (SUCCEEDED(hr)) 
        { 
            // Optional "context" parameter is not used in this example, 
            // and is set to nullptr. 
            hr = g_audioStateMonitor->RegisterCallback(OnAudioStateMonitorCallback, nullptr, &g_registration); 
        } 
    } 

    if (FAILED(hr)) 
    { 
        // g_audioStateMonitor is a smart pointer, so if an IAudioStateMonitor was 
        // allocated, setting the smart pointer to null invokes the Release method 
        // which will decrement its usage count and ensure that the object is properly 
        // destroyed. 
        g_audioStateMonitor = nullptr; 
    } 
    return hr; 
} 

// Unregister callbacks on program shutdown 
void UnregisterForSoundLevelChanges() 
{ 
    if (g_audioStateMonitor != nullptr) 
    { 
        if (g_registration) 
        { 
            g_audioStateMonitor->UnregisterCallback(g_registration); 
        } 

        // g_audioStateMonitor is a smart pointer, so setting it to null 
        // invokes the Release method to decrement its usage count. 
        g_audioStateMonitor = nullptr; 
    } 
} 

void OnAudioStateMonitorCallback(_In_ IAudioStateMonitor* audioStateMonitor, _In_opt_ void* context) 
{ 
    bool disableGameMediaStream = IsSoundLevelMuted(audioStateMonitor); 

    // Add code here that enables or disables the GameMedia stream based on the value 
    // of the boolean. 
} 
```

Um valor da enumeração [AudioStateMonitorSoundLevel](/pt-BR/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel). Indica o nível de som atual dos fluxos associados a [IAudioStateMonitor](/pt-BR/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor).

## Requisitos

**Cabeçalho:** Audiostatemonitorapi.h

**Plataformas compatíveis:** Windows, consoles da família XBOX One e consoles XBOX Series

## Confira também

[IAudioStateMonitor](/pt-BR/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)

[Sobre o WASAPI](https://learn.microsoft.com/windows/desktop/CoreAudio/wasapi)


## Related topics

- [Método IAudioStateMonitor::GetSoundLevel](/es/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
- [Enumeración AudioStateMonitorSoundLevel](/es/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel.md)
- [IAudioStateMonitor::GetSoundLevel method](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
- [IAudioStateMonitor::GetSoundLevel 方法](/zh-CN/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
- [IAudioStateMonitor::GetSoundLevel メソッド](/ja-jp/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
