音频文件未在通话中播放,而是在本地系统上播放-Skype for Business(C#)
我找到了一些代码,并对其进行了修改,使用skype拨打电话号码,播放音频文件,然后断开连接。但是,此代码中有两个问题音频文件未在通话中播放,而是在本地系统上播放-Skype for Business(C#),c#,phone-call,skype-for-business,C#,Phone Call,Skype For Business,我找到了一些代码,并对其进行了修改,使用skype拨打电话号码,播放音频文件,然后断开连接。但是,此代码中有两个问题 可以在本地系统上听到正在播放的音频文件 但不是在电话中(接听电话的人无法听到播放的音频) 音频文件完成后,呼叫未断开 玩 使用Microsoft.Lync.Model; 使用Microsoft.Lync.Model.Conversation; 使用Microsoft.Lync.Model.Conversation.AudioVideo; 使用Microsoft.Lync.Mode
使用Microsoft.Lync.Model;
使用Microsoft.Lync.Model.Conversation;
使用Microsoft.Lync.Model.Conversation.AudioVideo;
使用Microsoft.Lync.Model.Device;
使用Microsoft.Lync.Model.Extensibility;
使用制度;
使用System.Collections.Generic;
使用系统线程;
使用System.Windows.Forms;
命名空间LynchTest
{
公共部分类frmCaller:表单
{
公共frmCaller()
{
初始化组件();
}
私有void btnCall_单击(对象发送方,事件参数e)
{
//如果此客户端位于UISuppressionMode中。。。
if(client.InSuppressedMode&&client.State==ClientState.Uninitialized)
{
//…需要初始化它
尝试
{
client.BeginInitialize(this.ClientInitialized,null);
}
捕获(LyncClientException LyncClientException)
{
Console.WriteLine(lyncClientException);
}
捕获(系统异常系统异常)
{
if(LyncModelExceptionHelper.IsLyncException(系统异常))
{
//记录Lync模型API引发的异常。
Console.WriteLine(“错误:+systemException”);
}
其他的
{
//重新显示并非来自Lync模型API的SystemException。
投掷;
}
}
}
else//未在UI抑制中,因此客户端已初始化
{
//登录或联系人选择
SignInToLync();
}
SendLyncCall(“+6512345678”,“您好,我打电话是关于一个挂起的更改请求”);
}
LyncClient=LyncClient.GetClient();
私密无效登录Lync()
{
尝试
{
客户。BeginSignIn(“abc@contoso.com", "abc@contoso.com", "Pass@word99,HandleEndSignIn,null);
}
捕获(LyncClientException LyncClientException)
{
Console.WriteLine(lyncClientException);
}
捕获(系统异常系统异常)
{
if(LyncModelExceptionHelper.IsLyncException(系统异常))
{
//记录Lync模型API引发的异常。
Console.WriteLine(“错误:+systemException”);
}
其他的
{
//重新显示并非来自Lync模型API的SystemException。
投掷;
}
}
}
自动化_Automation=LyncClient.GetAutomation();
ConversationWindow globalConv=null;
public void SendLyncCall(字符串numberToCall、字符串textToSpeech)
{
var targetContactUris=新列表{numberToCall};/“电话:+490000000”
_automation.begintarconversation(automationmodelities.Audio、targetContactUris、null、StartConversationCallback、null);
while(this.globalConv==null)
{
睡眠(1);
}
if(globalConv!=null)
{
//client.DeviceManager.endPlayAudio文件(
//client.DeviceManager.BeginPlayAudioFile(@“C:\Temp\voice.wav”,AudioPlayBackModes.AlertAndCommunication,false,AudioPlayed,null)
// );
}
}
私有void StartConversationCallback(IAsyncResult异步操作)
{
//一旦拨号完成,就会调用此命令。。
if(asyncop.IsCompleted==true)
{
ConversationWindow newConversationWindow=\u automation.EndStartConversation(异步操作);
globalConv=新建对话窗口;
AVMODULE AVMODULE=newConversationWindow.Conversation.MODULES[ModalityTypes.AudioVideo]作为AVMODULE;
avModality.ModalityStateChanged+=会话modalitystatechangedcallback;
}
}
///
///在客户端完成初始化时调用。
///
///
私有无效客户端初始化(IAsyncResult结果)
{
//会话相关事件的寄存器
//这些事件将在创建(传入/传出)和删除新对话时发生
//client.ConversationManager.ConversationAdded+=ConversationManager\u ConversationAdded;
//client.ConversationManager.ConversationRemoved+=ConversationManager\u ConversationRemoved;
}
私有void会话ModalityStateChangedCallback(对象发送方,ModalityStateChangedEventArgs e)
{
AVMODULE AVMODULE=发送方作为AVMODULE;
if(avModality!=null)
{
开关(如NewState)
{
案例ModalityState.已断开:
avModality.ModalityStateChanged-=会话modalitystatechangedcallback;
打破
案例ModalityState。已连接:
avModality.ModalityStateChanged-=会话modalitystatechangedcallback;
//foreach(SOS中的字符c)
//{
//avModality.AudioChannel.BeginSendDtmf(c.ToString(),null,null);
//系统.线程.线程.睡眠(500);
//}
client.DeviceManager.EndPlayAudioFile(client.DeviceManager.BeginPlayAudioFile(@“C:\Temp\voice.wav”),
音频播放模式。通信,错误,音频播放,空);
打破
案例ModalityState。无效:
打破
案例ModalityState。已通知:
打破
}
}
}
专用void AudioPlayed(IAsyncResult AudioPlayed)
{
如果(audioPlayed.IsCompleted==true)
{
client.ConversationManager.Conversations[0].End();
}
}
私人无效手签(IAsyncResult ar)
{
尝试
{
委托人:EndSignIn(ar);
}
捕获(例外e)
{
控制台输出写入线(e);
}
}
私有无效frmCaller\u FormClosing(对象发送方,FormClosingEventArgs e)
{
GC.C
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
using Microsoft.Lync.Model.Conversation.AudioVideo;
using Microsoft.Lync.Model.Device;
using Microsoft.Lync.Model.Extensibility;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
namespace LyncTest
{
public partial class frmCaller : Form
{
public frmCaller()
{
InitializeComponent();
}
private void btnCall_Click(object sender, EventArgs e)
{
//if this client is in UISuppressionMode...
if (client.InSuppressedMode && client.State == ClientState.Uninitialized)
{
//...need to initialize it
try
{
client.BeginInitialize(this.ClientInitialized, null);
}
catch (LyncClientException lyncClientException)
{
Console.WriteLine(lyncClientException);
}
catch (SystemException systemException)
{
if (LyncModelExceptionHelper.IsLyncException(systemException))
{
// Log the exception thrown by the Lync Model API.
Console.WriteLine("Error: " + systemException);
}
else
{
// Rethrow the SystemException which did not come from the Lync Model API.
throw;
}
}
}
else //not in UI Suppression, so the client was already initialized
{
//sign-in or contact selection
SignInToLync();
}
SendLyncCall("+6512345678", "Hello, I am calling regarding a pending change request");
}
LyncClient client = LyncClient.GetClient();
private void SignInToLync()
{
try
{
client.BeginSignIn("abc@contoso.com", "abc@contoso.com", "Pass@word99", HandleEndSignIn, null);
}
catch (LyncClientException lyncClientException)
{
Console.WriteLine(lyncClientException);
}
catch (SystemException systemException)
{
if (LyncModelExceptionHelper.IsLyncException(systemException))
{
// Log the exception thrown by the Lync Model API.
Console.WriteLine("Error: " + systemException);
}
else
{
// Rethrow the SystemException which did not come from the Lync Model API.
throw;
}
}
}
Automation _automation = LyncClient.GetAutomation();
ConversationWindow globalConv = null;
public void SendLyncCall(string numberToCall, string textToSpeech)
{
var targetContactUris = new List<string> { numberToCall }; //"tel:+4900000000"
_automation.BeginStartConversation(AutomationModalities.Audio, targetContactUris, null, StartConversationCallback, null);
while (this.globalConv == null)
{
Thread.Sleep(1);
}
if (globalConv != null)
{
//client.DeviceManager.EndPlayAudioFile(
// client.DeviceManager.BeginPlayAudioFile(@"C:\Temp\voice.wav", AudioPlayBackModes.AlertAndCommunication, false, AudioPlayed, null)
// );
}
}
private void StartConversationCallback(IAsyncResult asyncop)
{
// this is called once the dialing completes..
if (asyncop.IsCompleted == true)
{
ConversationWindow newConversationWindow = _automation.EndStartConversation(asyncop);
globalConv = newConversationWindow;
AVModality avModality = newConversationWindow.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;
avModality.ModalityStateChanged += ConversationModalityStateChangedCallback;
}
}
/// <summary>
/// Called when the client in done initializing.
/// </summary>
/// <param name="result"></param>
private void ClientInitialized(IAsyncResult result)
{
//registers for conversation related events
//these events will occur when new conversations are created (incoming/outgoing) and removed
//client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
//client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
}
private void ConversationModalityStateChangedCallback(object sender, ModalityStateChangedEventArgs e)
{
AVModality avModality = sender as AVModality;
if (avModality != null)
{
switch (e.NewState)
{
case ModalityState.Disconnected:
avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
break;
case ModalityState.Connected:
avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
//foreach (char c in "SOS")
//{
// avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
// System.Threading.Thread.Sleep(500);
//}
client.DeviceManager.EndPlayAudioFile(client.DeviceManager.BeginPlayAudioFile(@"C:\Temp\voice.wav",
AudioPlayBackModes.Communication, false, AudioPlayed, null));
break;
case ModalityState.Invalid:
break;
case ModalityState.Notified:
break;
}
}
}
private void AudioPlayed(IAsyncResult audioPlayed)
{
if(audioPlayed.IsCompleted == true)
{
client.ConversationManager.Conversations[0].End();
}
}
private void HandleEndSignIn(IAsyncResult ar)
{
try
{
client.EndSignIn(ar);
}
catch (Exception e)
{
Console.Out.WriteLine(e);
}
}
private void frmCaller_FormClosing(object sender, FormClosingEventArgs e)
{
GC.Collect();
}
}
}