如何将 IAudioSessionControl 转换为 AudioSessionControl

How to convert IAudioSessionControl to AudioSessionControl

我正在使用 NAudio 包装器,我正在尝试在创建会话时将其静音。

MMDevice _device = _deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
_device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;

private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
{
        //mute session
}

为了使会话静音,我需要将其从 IAudioSessionControl 转换为 AudioSessionControl

IAudioSessionControl 是一个接口,因此我不知道如何转换它。

我们将不胜感激。

假设你的意思是 NAudio.CoreAudioApi.AudioSessionControl 有一个 constructor 它需要一个 IAudioSessionControl 作为参数并封装该接口。

private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
{
    AudioSessionControl audioSession = new AudioSessionControl(newSession);
    // mute
    audioSession.SimpleAudioVolume.Mute = true;
}

AudioSessionControl 对象包装 IAudioSessionControl COM 对象并根据其他可用接口公开附加功能。更直接的等价物可能是使用 ISimpleAudioVolume 接口:

ISimpleAudioVolume simpleAudioVolume = newSession as ISimpleAudioVolume;
if (simpleAudioVolume != null)
    simpleAudioVolume.Mute = true;