iOS 基于LinPhone的语音通话
创始人
2025-05-31 03:47:56
0

语音通话涉及到的概念介绍:

VoIP(Voice over Internet Protocol)即首先数字化语音信号并压缩成帧,转换为IP数据包在网络上传输,以此完成语音通话的业务,是一种利用IP协议传输语音数据的通信技术,VoIP通话中媒体流是走的UDP,一旦网络质量不好,语音的质量就会有延时或者断续,但是速度快。

Linphone是一款基于标准SIP的开源VoIP电话工具,是一款遵循GPL的开源的网络电话系统。它能够让你通过internet来查询朋友的IP,并通过IP给他打电话的软件,功能非常强大,既支持桌面系统,也支持移动终端,还能支持WEB浏览器。使用linphone,我们可以在互联网上随意的通信,通过语音、视频、即时文本消息。

Linphone基于ilbc的编解码;ilbc的编解码压缩比率还是比较大的,大概在1/10至1/9之间。也就是说假如每秒20kb的语音数据,编码后就2kb/s,非常小,非常利于网络传输。它使用了一个C库speex, 来实现回声消除模块。Linphone的最大优势在于全平台支持,android,ios,winphone,windows,linux,mac osx,web 全都支持


语音通话开发流程:

1)Cocoapods集成

Cocoapods 需要引入的开源三方库及版本:'linphone-sdk', ‘4.2’   'CocoaAsyncSocket', '7.6.5'

linphone-sdk:用于实际的语音通话功能

CocoaAsyncSocket:用于与后台建立链接,分配网络座席和通话状态改变监听(开通多少个座席要注意,这会涉及到不菲的价格...)

2)后台的简单介绍

因为不是我做的后台,我只能做简要的介绍,我们后台使用的语言是C++,如果不想付出太高的成本,又有比较高的效率, C++无疑是很好的选择。在语音通话过程中,客户端与后台会进行三大类型的交互:

1.向主管账号信息的服务器发送请求交互,获取与第二个服务器进行第二类和第三类交互要使用的数据模型

2.根据第一类与服务器交互获取的数据模型,LinPhoneSDK与服务器进行第二类交互,建立UDP链接,用于语音通话

3.根据第一类与后台交互获取的数据模型,使用客户端基于TCP/IP协议的socket网络库GCDAsyncSocket与后台进行第三类交互,建立链接,保持长链接,用于获取网络坐席和更改通话状态

3)客户端语音通话的各状态搭建分析

1.登录

I. 向主管账号信息的服务器发送请求, 传入对应的URL,账号和密码,使用AES加密(key和偏移量与后台协商一致),获取接下来要使用的数据模型

//向主管账号信息的服务器发送请求,建立链接,获取接下来要用到的数据模型
YGCallManager *manager = [YGCallManager instance];
[manager initSdk:model success:^(NSDictionary * _Nullable responseObject) {NSLog(@"initSdk:%@", responseObject);//与socket服务器和LinPhone服务器建立链接[[YGCallManager instance] login];} failure:^(NSError * _Nullable error) {NSLog(@"initSdk:%@", error);
}];

II. LinPhoneSDK与服务器建立第二类交互,建立UDP连接,为语音通话服务

ESSipManager *sipManager = [ESSipManager instance];
[sipManager login:@"你的LoginNum" password:@"你的pwd" displayName:@"" domain:@"你的sipIP:sipPort" port:@"你的sipPort" withTransport:@"UDP"];

III. 当Linphone登录成功,会调用成功的回调,这时socket与服务器建立第三类链接,为开通网络坐席和切换通话状态服务

sipManager.linphoneBlock = ^(NSInteger registrationState) {if (self.linphoneRegistrationState != registrationState) {self.linphoneRegistrationState = registrationState;if (registrationState == 2) {//2.socket连接self.clientSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];NSError *socketError = nil;if (![self.clientSocket connectToHost:self.tcpModel.TransferIP onPort:self.tcpModel.TransferPort withTimeout:-1 error:&socketError]) {if (socketError) {NSLog(@"连接服务器失败:%@", socketError.localizedDescription);return;}}

这里说的切换通话状态服务,也就是说接通和挂断等需要让客户端知道,以做到相应的处理,客户端接受状态的变化主要是通过socket的代理来实现

主要功能代码:

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {//接收登录服务消息if ([lastString containsString:@"LOGIN_SUCCEED"]) {//向app端推送EventLogin成功消息if (self.eventBlock) {NSDictionary *dic = @{@"msg":@"登录成功"};self.eventBlock(EVENTLogin, YES, dic);}//通知服务器当前账号的通道已经被占用NSData *data4 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:[NSString stringWithFormat:@"与后台协商好的信令服务"]];[self.clientSocket writeData:data4 withTimeout:-1 tag:4];}
}

IV. 做登录功能遇到的问题: 在一开始实现登录的时候发现多次登录会经常报用户正忙,无法登录。后来与后台联调,发现单点登录功能(也就是这次登录会把之前的登录踢下去)还不完善,针对socket接口进行了优化升级.流程修改为: 发送准备状态给语音通话的服务器 => 发送初始化消息给分配座席服务器 => 发送清理通道消息给服务器 =》 发送登录消息给服务器

实现功能的部分代码(主要是发送与后台协商好的socket):

//登录
- (void)ygTcpLogin {//发送准备状态给服务器NSData *data = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"与后台约定好的信令服务"];[self.clientSocket writeData:data withTimeout:-1 tag:0];//发送初始化消息给转发服务器NSData *data1 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"与后台约定好的信令服务"];[self.clientSocket writeData:data1 withTimeout:-1 tag:1];//发送清理通道消息给服务器NSData *data2 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"与后台约定好的信令服务"];[self.clientSocket writeData:data2 withTimeout:-1 tag:2];//发送登录消息给服务器NSData *data3 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"与后台约定好的信令服务"];[self.clientSocket writeData:data3 withTimeout:-1 tag:3];
}

V.  做登陆功能遇到的问题2: iOS16以上的版本Linphone与语音通话后台无法建立链接,原因是端口存在被占用的可能。解决方式是每次链接时,给LinPhone分配未被占用的随机端口

实现的功能的部分代码:

    [LinphoneManager.instance resetLinphoneCore];LinphoneProxyConfig *config = linphone_core_create_proxy_config(LC);LinphoneAddress *addr = linphone_address_new([NSString stringWithFormat:@"sip:%@@%@",username, domain].UTF8String);LinphoneAddress *tmpAddr = linphone_address_new([NSString stringWithFormat:@"sip:%@",domain].UTF8String);linphone_address_set_username(addr, username.UTF8String);linphone_address_set_port(addr, linphone_address_get_port(tmpAddr));linphone_address_set_domain(addr, linphone_address_get_domain(tmpAddr));if (displayName && ![displayName isEqualToString:@""]) {linphone_address_set_display_name(addr, displayName.UTF8String);}linphone_proxy_config_set_identity_address(config, addr);if (transport) {linphone_proxy_config_set_route(config,[NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, transport.lowercaseString.UTF8String].UTF8String);linphone_proxy_config_set_server_addr(config,[NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, transport.lowercaseString.UTF8String].UTF8String);}linphone_proxy_config_enable_publish(config, FALSE);linphone_proxy_config_enable_register(config, TRUE);LinphoneAuthInfo *info =linphone_auth_info_new(linphone_address_get_username(addr), // usernameNULL,                                // user idpassword.UTF8String,                        // passwdNULL,                                // ha1linphone_address_get_domain(addr),   // realm - assumed to be domainlinphone_address_get_domain(addr)    // domain);linphone_core_add_auth_info(LC, info);linphone_address_unref(addr);linphone_address_unref(tmpAddr);//分配随机端口LCSipTransports transportValue = {-1,-1,-1,-1};if (linphone_core_set_sip_transports(LC, &transportValue)) {NSLog(@"cannot set transport");}

2.外呼

I. 外呼功能流程:客户端拨打 => 通知服务器将当前账号置于繁忙状态并分配座席 => 客户端收到转座席是否成功的socket回调并做相应的处理, 同时服务器(语音后台)发送虚拟号码和被呼叫的号码等相关信息给Lin Phone,通知Linphone拨打网络电话 

实现外呼功能的部分代码(客户端主要是把自己和被呼叫者的信息发给后台,LinPhone拨打电话实际是由后台触发的):

//当前账号置为繁忙
NSData *data8 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"繁忙信令"];
[self.clientSocket writeData:data8 withTimeout:-1 tag:8];//分配座席,并建立语音通话链接
NSData *data9 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:@"座席建立链接信令"];
[self.clientSocket writeData:data9 withTimeout:-1 tag:9];

II.外呼动作完成后,就需要等待被呼叫者,看其是否接听,这就需要监听通话状态的改变,这里是由LinPhone提供的状态变化的宏来实现的,我们需要对这个后果进行通知监听,一旦监听到状态变化,调用LinPhone相关的API来进行接听或挂断。

实现功能的部分代码:

//监听通话状态变化
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onCallUpdate:) name:kLinphoneCallUpdate object:nil];- (void) onCallUpdate: (NSNotification*) notification {NSDictionary* userInfo = [notification userInfo];NSValue* c = [userInfo valueForKey:@"call"];//    int state = (int)[userInfo valueForKey:@"state"];LinphoneCallState state = [[userInfo objectForKey:@"state"] intValue];NSString* message = [userInfo valueForKey:@"message"];NSLog(@"========== state: %d, message: %@", state, message);LinphoneCall* call = c.pointerValue;NSDictionary *dict = @{@"call" : [NSValue valueWithPointer:call],@"state" : [NSNumber numberWithInt:state],@"message" : message};switch (state) {//接听case LinphoneCallIncomingReceived: {[NSNotificationCenter.defaultCenter postNotificationName:ES_ON_CALL_COMMING object: self userInfo:dict];if (self.callBlock) {self.callBlock((NSInteger)state, dict);}break;}case LinphoneCallOutgoingInit:case LinphoneCallConnected:case LinphoneCallStreamsRunning: {// check videoif (![self isVideoEnabled:call]) {const LinphoneCallParams *param = linphone_call_get_current_params(call);const LinphoneCallAppData *callAppData =(__bridge const LinphoneCallAppData *)(linphone_call_get_user_data(call));if (state == LinphoneCallStreamsRunning && callAppData->videoRequested &&linphone_call_params_low_bandwidth_enabled(param)) {// too bad video was not enabled because low bandwidthNSLog(@"带宽太低,无法开启视频通话");callAppData->videoRequested = FALSE; /*reset field*/}}[NSNotificationCenter.defaultCenter postNotificationName:ES_ON_CALL_STREAM_UPDATE object:self userInfo:dict];break;}case LinphoneCallUpdatedByRemote: {const LinphoneCallParams *current = linphone_call_get_current_params(call);const LinphoneCallParams *remote = linphone_call_get_remote_params(call);/* remote wants to add video */if ((linphone_core_video_display_enabled([LinphoneManager getLc]) && !linphone_call_params_video_enabled(current) &&linphone_call_params_video_enabled(remote)) &&(!linphone_core_get_video_policy([LinphoneManager getLc])->automatically_accept ||(([UIApplication sharedApplication].applicationState != UIApplicationStateActive) &&floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max))) {linphone_core_defer_call_update([LinphoneManager getLc], call);[NSNotificationCenter.defaultCenter postNotificationName:ES_ON_REMOTE_OPEN_CEMERA object: self userInfo:dict];//                     [self allowToOpenCameraByRemote:call];} else if (linphone_call_params_video_enabled(current) && !linphone_call_params_video_enabled(remote)) {}break;}case LinphoneCallUpdating:break;case LinphoneCallPausing:case LinphoneCallPaused:break;case LinphoneCallPausedByRemote:break;//挂断case LinphoneCallEnd: {//LinphoneCallEnd[NSNotificationCenter.defaultCenter postNotificationName:ES_ON_CALL_END object: self userInfo:NULL];if (self.callBlock) {self.callBlock((NSInteger)state, dict);}break;}case LinphoneCallReleased: {if (self.callBlock) {self.callBlock((NSInteger)state, dict);}break;}case LinphoneCallError:default:break;}
}

当触发callBlock后,就会调用LinPhone相应的接听的方法:

- (void)acceptCall:(LinphoneCall *)call evenWithVideo:(BOOL)video {LinphoneCallParams *lcallParams = linphone_core_create_call_params(theLinphoneCore, call);if (!lcallParams) {LOGW(@"Could not create call parameters for %p, call has probably already ended.", call);return;}if ([self lpConfigBoolForKey:@"edge_opt_preference"]) {bool low_bandwidth = self.network == network_2g;if (low_bandwidth) {LOGI(@"Low bandwidth mode");}linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth);}linphone_call_params_enable_video(lcallParams, video);linphone_call_accept_with_params(call, lcallParams);linphone_call_params_unref(lcallParams);
}

此时,一个呼叫-接听的流程就已经建立,接下来就要说到挂断了,因为有接听,必然就有挂断

3.挂断

挂断分为两类,一类是己方主动挂断,另一类是对方挂断,这是两种不同的处理方式

I. 己方挂断

流程: 己方点击挂断 => 通知后台己方挂断,即将执行挂断流程 => 通知LinPhone执行挂断 => LinPhone执行挂断后通知语音服务器执行挂断处理 => 语音服务器通知与socket进行长链接的服务器进行挂断处理 => 与socket进行长链接的服务器会给客户端回调,设置完全通话结束socket信令给socket服务器,并设置己方处于空闲状态 => 语音服务器会给Linphone发送通话完全结束,Linphone清理本次通话数据并通知客户端,进行本地通话数据清理

开始通知后台执行己方挂断,并且通知Linphone结束通话的部分代码:

 NSData *data20 = [self sendMsgWithName:self.tcpModel.PhoneNo type:@"" targetType:@"" msg:[NSString stringWithFormat:@"开始结束通话信令服务"];LinphoneCore* lc = [LinphoneManager getLc];LinphoneCall* currentcall = linphone_core_get_current_call(lc);if (linphone_core_is_in_conference(lc) || // In conference(linphone_core_get_conference_size(lc) > 0) // Only one conf) {linphone_core_terminate_conference(lc);} else if(currentcall != NULL) { // In a call
//        linphone_core_terminate_call(lc, currentcall);linphone_call_terminate(currentcall);} else {const MSList* calls = linphone_core_get_calls(lc);if (ms_list_size(calls) == 1) { // Only one call
//            linphone_core_terminate_call(lc,(LinphoneCall*)(calls->data));linphone_call_terminate((LinphoneCall *)(calls->data));}}

后台收到结束通话信令,并且通知客户端传送结束的socket信息,客户端向后台发送己方置为空闲的部分代码:

//设置话后NSData *data11 = [self sendMsgWithName:@"" type:@"" targetType:@"FlyCcs" msg:[NSString stringWithFormat:@"话后信令"]];[self.clientSocket writeData:data11 withTimeout:-1 tag:11];//设置话后提交NSData *data12 = [self sendMsgWithName:@"" type:@"" targetType:@"FlyCcs" msg:[NSString stringWithFormat:@"话后提交信令"]];[self.clientSocket writeData:data12 withTimeout:-1 tag:12];//空闲NSData *data19 = [self sendMsgWithName:self.tcpModel.PhoneNo type:@"FlyCcs" targetType:@"FlyCcs" msg:[NSString stringWithFormat:@"空闲信令"]];[self.clientSocket writeData:data19 withTimeout:-1 tag:19];

LinPhone发送彻底消除通话的通知,客户端执行本地通话的数据清理的部分代码:

case LinphoneCallReleased: {if (self.callBlock) {self.callBlock((NSInteger)state, dict);}break;}sipManager.callBlock = ^(NSInteger callState, NSDictionary *dict) {if (self->_ISDIALOUT == 0) {return;}if (callState == 1) {NSLog(@"接听--callState == 1");LinphoneCall *call = [dict[@"call"] pointerValue];[weakManager acceptCall:(ESCall *)call];} else if (callState == 18) {NSLog(@"挂断--callState == 18");//向app端推送EventHangup
//            if (self.eventBlock) {
//                NSDictionary *dic = @{@"CallId":@"",
//                                      @"CallTime":@"",
//                                      @"CodeCause":@"",
//                                      @"ConnectTime":@"",
//                                      @"EndTime":@"",
//                                      @"Rebark":self.Rebark ? self.Rebark : @"",
//                                      @"SignalIng":@"",
//                                      @"WavFile":self.WavFile ? self.WavFile : @""
//                };
//                self.eventBlock(EVENTHangup, YES, dic);
//            }//清空本地数据self->_callModel = nil;self->_CallId = nil;self->_ConnectTime = nil;self->_Rebark = nil;self->_WavFile = nil;self->_ISDIALOUT = 10;}

II. 对方挂断 

流程;对方挂断 => LinPhone通知客户端挂断 => LinPhone通知服务器通话挂断 => 服务器通知客户端发动结束通话,置为空闲的信令 => 服务器通知LinPhone消除本次通话数据 => LinPhone通知客户端消除本次通话数据

实现功能的关键代码与己方挂断代码是相同的,所以就不列举了

4.来电

流程: LinPhone收到来电通知 => 通知服务器和客户端回调收到来电 => 服务器通过socket代理通知客户端来电和相关来电消息 => 客户端发送繁忙信令和转发分配座席信令 =>通话信道建立完毕

实现功能的部分代码(与上面重复的部分省略):


//繁忙信令
NSData *data13 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:[NSString stringWithFormat:@"当前账号置为繁忙的信令"]]; //与data10一样;[self.clientSocket writeData:data13 withTimeout:-1 tag:13];//分配座席信令        
NSData *data14 = [self sendMsgWithName:@"" type:@"" targetType:@"FlyCn" msg:[NSString stringWithFormat:@"转发分配座席的信令"]; //与data10一样[self.clientSocket writeData:data14 withTimeout:-1 tag:14];

4.接听

 实现主要功能的部分代码:

LinphoneCallParams *lcallParams = linphone_core_create_call_params(theLinphoneCore, call);if (!lcallParams) {LOGW(@"Could not create call parameters for %p, call has probably already ended.", call);return;}if ([self lpConfigBoolForKey:@"edge_opt_preference"]) {bool low_bandwidth = self.network == network_2g;if (low_bandwidth) {LOGI(@"Low bandwidth mode");}linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth);}linphone_call_params_enable_video(lcallParams, video);linphone_call_accept_with_params(call, lcallParams);linphone_call_params_unref(lcallParams);

听筒/扬声器切换 静音切换 保持通话

还有就是一些比较细小的功能,比如听筒/扬声器切换,静音切换

//听筒/扬声器切换
- (void)speakerToggle {//true:开启扬声器; false:关闭扬声器[LinphoneManager.instance setSpeakerEnabled:self->speaker];self->speaker = !self->speaker;
}//静音切换
- (void)muteToggle {//true:开启静音; false:关闭静音linphone_core_enable_mic(LC, self->mute);self->mute = !self->mute;
}

还有就是先忙其他事,保持当前通话,对方听不到声音:

流程:客户端向服务器发送保持当前通话信令 => 客户端向服务器发送保持繁忙状态信令 => 语音服务区通知LinPhone进入保持当前通话状态

//保持
- (void)holdCall {NSData *data30 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:[NSString stringWithFormat:@"保持通话信令"];[self.clientSocket writeData:data30 withTimeout:-1 tag:30];NSData *data31 = [self sendMsgWithName:@"" type:@"" targetType:@"" msg:[NSString stringWithFormat:@"保持繁忙状态信令"];[self.clientSocket writeData:data31 withTimeout:-1 tag:31];//向app端推送状态事件EventAgentStateif (self.eventBlock) {}self.flag = ([self.flag isEqualToString:@"HOLDCALL"]) ? @"REHOLDCALL" : @"HOLDCALL";
}

语音通话后台保活的实现

 通话过程中的保活已经由LinPhone底层实现,但是没有通话还处于后台模式,怎么保活来保证收到来电和播放响铃呢,这里的响铃不是微信里的通知短暂响铃,而是长时间的响铃,我这边的实现方式主要是基于播放无声音乐

I. LinPhone给客户端状态回调,通知来电,在来电的回调里调用播放长时间响铃 ,挂断电话时,在回调里通知挂断,然后结束播放铃声

manager.eventBlock = ^(EVENT event, BOOL result, NSDictionary * _Nonnull resultMsg) {switch (event) {case EVENTAgentState: {//状态变化事件,下一行注释均为回调具体参数[[NSNotificationCenter defaultCenter] postNotificationName:kEVENTAgentState object:nil userInfo:resultMsg];}break;case EVENTLogin: {//登录成功事件if (result) {ViewController *vc = [[ViewController alloc] init];[self.navigationController pushViewController:vc animated:YES];} else {sender.enabled = YES;[self alertWithMessage:@"登录失败,请重新登录"];}}break;case EVENTQuitLogin: {//退出登录或工号异处登录事件[[NSNotificationCenter defaultCenter] postNotificationName:kEVENTQuitLogin object:nil userInfo:resultMsg];}break;case EVENTMakeCall: {//外呼事件}break;case EVENTComeCall: {//来电事件[[NSNotificationCenter defaultCenter] postNotificationName:kComeCallUpdate object:nil userInfo:resultMsg];AVAudioSession *audioSession = [AVAudioSession sharedInstance];// 设置多声道播放NSError *error = nil;[audioSession setCategory:AVAudioSessionCategoryMultiRoute withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];[[ZSAVPlayerInstance sharedInstance] start];}break;case EVENTCalling: {//通话中事件[[ZSAVPlayerInstance sharedInstance] stop];AVAudioSession *audioSession = [AVAudioSession sharedInstance];// 设置后台播放NSError *error = nil;[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];}break;case EVENTHangup: {//挂机事件[[NSNotificationCenter defaultCenter] postNotificationName:kEVENTHangup object:nil userInfo:resultMsg];[[ZSAVPlayerInstance sharedInstance] stop];AVAudioSession *audioSession = [AVAudioSession sharedInstance];// 设置后台播放NSError *error = nil;[audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];}break;default:break;}[resultMsg enumerateKeysAndObjectsUsingBlock:^(id key,id obj, BOOL *stop) {NSLog(@"event:%d key:%@ value:%@", (int)event, key, obj);}];};

II.问题:

在这个过程中,遇到的问题是后台保活音乐和铃声播放存在冲突,后台保活音乐要设置AVAudioSession为AVAudioSessionCategoryPlayback后台播放模式,铃声在这种模式下无法播放,播放铃声要设置为AVAudioSessionCategoryMultiRoute多声道模式, 等到接听铃声播放结束再设置为AVAudioSessionCategoryPlayback后台播放模式,

播放器部分代码:

static ZSAVPlayerInstance *instance;
static dispatch_once_t onceToken;
+ (instancetype)sharedInstance {dispatch_once(&onceToken, ^{instance = [ZSAVPlayerInstance new];});return instance;
}- (void)setup {[self setupAudioSession];[self setupAudioPlayer];
}- (void)setupAudioSession {// 新建AudioSession会话AVAudioSession *audioSession = [AVAudioSession sharedInstance];// 设置多声道混合播放NSError *error = nil;[audioSession setCategory:AVAudioSessionCategoryMultiRoute withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];if (error) {NSLog(@"Error setCategory AVAudioSession: %@", error);}NSLog(@"%d", audioSession.isOtherAudioPlaying);NSError *activeSetError = nil;// 启动AudioSession,如果一个前台app正在播放音频则可能会启动失败[audioSession setActive:YES error:&activeSetError];if (activeSetError) {NSLog(@"Error activating AVAudioSession: %@", activeSetError);}
}- (void)setupAudioPlayer {//铃声文件self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"notes_of_the_optimistic" withExtension:@"caf"] error:nil];//音量self.audioPlayer.volume = 1.0;//播放多次self.audioPlayer.numberOfLoops = -1;[self.audioPlayer prepareToPlay];
}#pragma mark - public method- (void)start {NSLog(@"--ringUrl:%@", self.ringUrl.absoluteString);[self setupAudioSession];[self setupAudioPlayer];if (!self.audioPlayer.isPlaying) {[self.audioPlayer play];}
}- (void)stop {[self.audioPlayer stop];
}

结语

语音通话的主要知识点就是这些,还有一些其他的就需要结合具体业务流程就不方便说了,视频通话也可以使用LinPhone,有时间再写吧,感觉有帮助的话给个star吧!

相关内容

热门资讯

走进小城看消费丨江西资溪:低碳...   夏日时节下午4点,江西省抚州市资溪县大觉山景区漂流终点依然热闹。来自南昌的游客余鑫漂流结束后没有...
【中原晨会0625】市场分析专... 来源:市场资讯 (来源:中原证券研究所) 本期重点研报目录 【中原策略】市场分析:电子半导体领涨 ...
南向资金连买4日!低费率+可月... 6月25日早盘,港股红利资产震荡整理。截至11时14分,港股红利低波ETF招商(520550)下跌0...
618成交破百万!紫荆花用一套... 一年一度的618年中大促,是消费市场的晴雨表,也是品牌间最激烈的角力场。当各大品牌在直播间里铆足了劲...
原创 黄... 2026年6月25日的国际金价已经从前期的5500美元高点跌到4200美元下方,累计跌幅超过22%,...
英伟达CEO:Vera Rub... 截至9:38,中证半导体材料设备主题指数(931743)涨2.36%创新高;权重股中,中微公司涨3....
再被催债16亿!“钢铁大王”戴... 澎湃新闻记者 贺梨萍 因“铁本事件”入狱五年的戴国芳重返钢铁行业,但他并没有完成从阶下囚再到“钢铁大...
周三原油价格下跌 随着美国和伊朗在和平谈判中取得进展,越来越多的油轮公开穿越霍尔木兹海峡,原油在战时的价格上涨已经蒸发...
这种蛋白是大脑衰老的开关 这种蛋白是大脑衰老的开关 清晨,假设一位五十岁左右的王女士发现自己常常把手机放在熟悉的抽屉里又找不到...
信通院牵头算力Token出海生... 盘面上,截至11:04,中证科创创业50指数(931643)涨1.68%,创历史新高;权重股中,芯原...
海外 774 亿营收背后:日本... 文 | 游戏价值论 6月23日,彭博社报道了腾讯正在围绕出售多家日本游戏工作室少数股权开展谈判,包...
餐饮“抢人”大战:把店开到公交... 作者 |餐饮老板内参 内参君 医院、公交站、演唱会…餐饮品牌,正在无孔不入 在北京儿童医院,肯德基...
快讯 | 外资扫货!陈翊庭:港... 港交所行政总裁陈翊庭在接受《中国证券报》专访时指出,国际资本对中国资产的看法已彻底扭转,布局中国市场...
2777.77元!A股“股王”... 25日早盘,昨天创下历史新高的A股“股王”联讯仪器,今天上午继续走强,盘中股价再度刷新历史新高。 截...
原创 今... 欧洲自己的媒体直接下结论,欧盟衰退躲不掉,内部分裂拦不住,现在就连欧洲顶尖工业巨头,都偷偷在用中国的...
黄仁勋股东大会放言:本轮AI基... 在当地时间6月24日的英伟达(NVDA.O)2026年度股东大会上,股东批准了该公司全部10名董事会...
国际油价大跌 新华社消息, 纽约原油期货主力合约价格24日盘中跌破每桶70美元,为伊朗战事爆发以来首次。 市场分析...
马云带队插秧,什么信号? 一场别开生面的“务农”,让外界看到了一个不一样的阿里巴巴。 近日,阿里巴巴合伙人、高德董事长刘振飞在...
全球最大产能,最高丰度达99.... 本文转自【科技日报】; 6月23日,高丰度硼-10同位素技术暨产业化成果发布会在山东省东营市举办,全...
黄金大跳水!金饰克价年内暴跌近... 25日,现货黄金盘中震荡,截至发稿,报3985.070美元/盎司,跌0.17%。 当地时间24日,...