0
當音頻會話以NAudio開始和結束時,我希望收到回調。以下代碼正在工作:使用NAudio爲狀態更改接收音頻會話回調
private void SetupMediaSessionCallbacks()
{
// Foreach output endpoint
foreach (var md in new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active))
{
md.AudioSessionManager.OnSessionCreated += OnSessionCreated;
}
}
此代碼在創建新音頻會話時觸發。我是新來的n音訊,所以我不知道如何設置RegisterEventClient接收狀態更改事件:
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
// Not working, need help here!
AudioSessionControl audioSession = new AudioSessionControl(newSession);
IAudioSessionEventsHandler handler = null;
AudioSessionEventsCallback notifications = new AudioSessionEventsCallback(test);
handler.OnStateChanged += new EventHandler<AudioSessionState>(notifications_StateChanged);
audioSession.RegisterEventClient(handler);
}
這裏的回調,我相信這是正確的:
void notifications_StateChanged(object sender, AudioSessionState newState)
{
if (newState == AudioSessionState.AudioSessionStateActive)
{
Console.WriteLine("StateChanged");
}
}
任何幫助將不勝感激。我已經搜索了這個文件的高和低。