我是 UCMA 的新手,我正在通过示例学习。我正在尝试使用以下场景构建 2 个 Lync 客户端 A 和 B,
- A呼叫B
- B 答案
- A 播放音频
- B 使用 Recorder 记录它。
我一直在尝试在 B 处记录通话。对于 B,它是来电。我需要将音频视频流附加到录音机,但我不知道该怎么做。我将不胜感激。对未格式化的代码表示歉意,我不知道如何正确格式化它,我试过了。
谢谢。克里斯
客户 B 代码:
- 接听来电
记录来电中收到的媒体。***这是我遇到麻烦的部分
使用系统;使用 System.Threading;使用 Microsoft.Rtc.Collaboration;使用 Microsoft.Rtc.Collaboration.AudioVideo;使用 Microsoft.Rtc.Signaling;使用 Microsoft.Rtc.Collaboration.Lync;
命名空间 Microsoft.Rtc.Collaboration.LyncUAS { public class LyncUAS { #region Locals private LyncUASConfigurationHelper _helper; 私有用户端点_userEndpoint;私人 AudioVideoCall _audioVideoCall; 私有 AudioVideoFlow _audioVideoFlow; 私人对话_incomingConversation;
//Wait handles are only present to keep things synchronous and easy to read. private AutoResetEvent _autoResetEvent = new AutoResetEvent(false); private EventHandler<AudioVideoFlowConfigurationRequestedEventArgs> _audioVideoFlowConfigurationRequestedEventHandler; private EventHandler<MediaFlowStateChangedEventArgs> _audioVideoFlowStateChangedEventHandler; private AutoResetEvent _waitForAudioVideoCallEstablishCompleted = new AutoResetEvent(false); private AutoResetEvent _waitForAudioVideoFlowStateChangedToActiveCompleted = new AutoResetEvent(false); private AutoResetEvent _waitForPrepareSourceCompleted = new AutoResetEvent(false); #endregion #region Methods /// <summary> /// Instantiate and run the DeclineIncomingCall quickstart. /// </summary> /// <param name="args">unused</param> public static void Main(string[] args) { LyncUAS lyncUAS = new LyncUAS(); lyncUAS.Run(); } private void Run() { string filename = "received.wma"; _helper = new LyncUASConfigurationHelper(); // Create a user endpoint, using the network credential object // defined above. _userEndpoint = _helper.CreateEstablishedUserEndpoint("Lync UAS" /*endpointFriendlyName*/); _userEndpoint.RegisterForIncomingCall<AudioVideoCall>(On_AudioVideoCall_Received); Console.WriteLine("Waiting for incoming call..."); _autoResetEvent.WaitOne(); Console.WriteLine("came after call is connected"); //start recording for audio. Recorder recorder = new Recorder(); recorder.StateChanged += new EventHandler<RecorderStateChangedEventArgs>(recorder_StateChanged); recorder.VoiceActivityChanged += new EventHandler<VoiceActivityChangedEventArgs>(recorder_VoiceActivityChanged);
//**********这是问题,当前_audioVideoFlow为空,它没有附加到流 //所以这会失败,如何附加_audioVideoFlow到来电?帮助 !!!
// recorder.AttachFlow(_audioVideoFlow); ------------> HELP! WmaFileSink sink = new WmaFileSink(filename); recorder.SetSink(sink); recorder.Start(); Console.WriteLine("Started Recording ..."); _autoResetEvent.WaitOne(); recorder.Stop(); Console.WriteLine("Stopped Recording ..."); recorder.DetachFlow(); Console.WriteLine("Exiting"); Thread.Sleep(2000); } private void audioVideoFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e) { Console.WriteLine("Flow state changed from " + e.PreviousState + " to " + e.State); //When flow is active, media operations can begin if (e.State == MediaFlowState.Active) { // Flow-related media operations normally begin here. _waitForAudioVideoFlowStateChangedToActiveCompleted.Set(); } // call sample event handler if (_audioVideoFlowStateChangedEventHandler != null) { _audioVideoFlowStateChangedEventHandler(sender, e); } } void recorder_VoiceActivityChanged(object sender, VoiceActivityChangedEventArgs e) { Console.WriteLine("Recorder detected " + (e.IsVoice ? "voice" : "silence") + " at " + e.TimeStamp); } void recorder_StateChanged(object sender, RecorderStateChangedEventArgs e) { Console.WriteLine("Recorder state changed from " + e.PreviousState + " to " + e.State); } void On_AudioVideoCall_Received(object sender, CallReceivedEventArgs<AudioVideoCall> e) { //Type checking was done by the platform; no risk of this being any // type other than the type expected. _audioVideoCall = e.Call; // Call: StateChanged: Only hooked up for logging, to show the call // state transitions. _audioVideoCall.StateChanged += new EventHandler<CallStateChangedEventArgs>(_audioVideoCall_StateChanged); _incomingConversation = new Conversation(_userEndpoint); Console.WriteLine("Call Received! From: " + e.RemoteParticipant.Uri + " Toast is: " +e.ToastMessage.Message); _audioVideoCall.BeginAccept( ar => { try { _audioVideoCall.EndAccept(ar); Console.WriteLine("Call must be connected at this point. "+_audioVideoCall.State); _autoResetEvent.Set(); } catch (RealTimeException ex) { Console.WriteLine(ex); } }, null); } //Just to record the state transitions in the console. void _audioVideoCall_StateChanged(object sender, CallStateChangedEventArgs e) { Console.WriteLine("Call has changed state. The previous call state was: " + e.PreviousState + " and the current state is: " + e.State); if (e.State == CallState.Terminated) { Console.WriteLine("Shutting down"); _autoResetEvent.Set(); _helper.ShutdownPlatform(); } } #endregion }
}