无法在ios代码中记录PJSIP呼叫。我正在使用PJSIP 2.2版本。 以下是我的代码
pjsua_recorder_id recorder_id;
pj_status_t status;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [NSString stringWithFormat:@"%@/mysong.wav", documentsDirectory];
pj_str_t fileName = pj_str([strPath UTF8String]);
status = pjsua_recorder_create(&fileName, 0, NULL, 0, 0, &recorder_id);
NSLog(@"status is = %i", status);
int way = 1 << 0;
static int BITMASK_IN = 1 << 0;
static int BITMASK_OUT = 1 << 1;
if(status == PJ_SUCCESS)
{
pjsua_recorder_id recorder_id;
pj_status_t status;
int wavPort = pjsua_recorder_get_conf_port(0);
if ((way & BITMASK_IN) == BITMASK_IN) {
int wavConfPort = -1;//callInfo.getConfPort();
pjsua_conf_connect(0, wavPort);
}
if ((way & BITMASK_OUT) == BITMASK_OUT) {
pjsua_conf_connect(0, wavPort);
}
wavPort = pjsua_call_get_conf_port(0);
pjsua_conf_connect(0, wavPort);
status = pjsua_recorder_create(&fileName, 0, NULL, 0, 0, &recorder_id);
NSLog(@"final status is = %i", status);
}
Status的值为0(PJ_SUCCESS),但仍然无法播放.wav文件。要播放.wav文件,
// get files list
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"Array of files = %@", directoryContents);
//Play audio file
NSString *soundFilePath = [NSString stringWithFormat:@"%@/mysong.wav",documentsDirectory];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:soundFileURL options:nil];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:NULL];
theAudio.volume = 1.0;
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio play];
在文件数组中,我能够记录.wav文件。