> ## 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::UnregisterCallback

> Método IAudioStateMonitor::UnregisterCallback

# Método IAudioStateMonitor::UnregisterCallback

Anula el registro de una devolución de llamada registrada previamente con  [IAudioStateMonitor::RegisterCallback](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-registercallback).

## Sintaxis

```cpp theme={null}
void UnregisterCallback(
  AudioStateMonitorRegistrationHandle registration
);
```

### Parámetros

*registration*<br />Tipo: AudioStateMonitorRegistrationHandle

Un entero de 64 bits que identifica la devolución de llamada cuyo registro se va a anular. Este valor se devuelve en el parámetro *registration* del método **RegisterCallback**.

### Valor devuelto

Este método no devuelve ningún valor.

## Comentarios

Considere el siguiente escenario, en el que un juego elige reproducir audio GameMedia solo cuando se sabe que el sistema operativo no silenciará el audio debido a la directiva. Para lograrlo, el juego se registra para recibir notificaciones de SoundLevel de la categoría de secuencia [AudioCategory\_GameMedia](https://learn.microsoft.com/windows/desktop/api/audiosessiontypes/ne-audiosessiontypes-audio_stream_category) en el punto de conexión de consola predeterminado. Si el SoundLevel de esta categoría se establece en 'Muted', el juego detendrá la reproducción de su secuencia GameMedia. Si el SoundLevel se establece en cualquier otro valor, el juego elige reproducir su secuencia 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. 
} 
```

## Requisitos

**Encabezado:** Audiostatemonitorapi.h

**Plataformas compatibles:** Windows, consolas de la familia XBOX One y consolas XBOX Series

## Consulte también

[IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)

[Acerca de WASAPI](https://learn.microsoft.com/en-us/windows/desktop/CoreAudio/wasapi)


## Related topics

- [Método IAudioStateMonitor::RegisterCallback](/es/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-registercallback.md)
- [Método IAudioStateMonitor::GetSoundLevel](/es/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
- [Interfaz IAudioStateMonitor](/es/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor.md)
- [AudioStateMonitorRegistrationHandle](/es/reference/audio/audiostatemonitor/types/audiostatemonitorregistrationhandle.md)
- [IGameInput::UnregisterCallback](/es/reference/input/gameinput/interfaces/igameinput/methods/igameinput_unregistercallback.md)
