我正在使用webrtc
在iOS中处理VOIP。
如何为拨出电话产生拨号音,即如何在耳前扬声器中产生铃声,直到拨出电话连接?
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/TEST.aif", [[NSBundle mainBundle] resourcePath]]];
AVAudioPlayer * keepAwakePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
UInt32 doSetProperty = TRUE;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
keepAwakePlayer.numberOfLoops = -1;
[keepAwakePlayer play];
我可以想到两种方法。
- 播放录制的音频文件。
- 按需创建声波。AFAIK,电话播放音符A的正弦波,即440赫兹。您可以创建波次并在末尾添加大量零添加沉默。然后循环播放,直到接听电话。
基于Maverick的回答。这将像在电话中一样在耳机扬声器中播放铃声(适用于iOS 10.3)。
NSError *av_error = nil;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/digitalphone.caf", [[NSBundle mainBundle] resourcePath]]];
av_Player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&av_error];
NSError *sesionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:kAudioSessionProperty_OverrideAudioRoute error:&sesionError];
av_Player.numberOfLoops = -1;
[av_Player play];