Can AVAudioSession do full duplex?

Posted by Eric Christensen on Stack Overflow See other posts from Stack Overflow or by Eric Christensen
Published on 2010-03-15T05:37:29Z Indexed on 2010/03/15 5:39 UTC
Read the original article Hit count: 537

It would seem like it should be able to, but the following breakout test code can't do both:

//play a file:
NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [pathsArray objectAtIndex:0];
NSString* playFilePath=[documentsDirectory stringByAppendingPathComponent:@"testplayfile.wav"];
AVAudioPlayer *tempplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:playFilePath] error:nil];
[tempplayer prepareToPlay];
[tempplayer play];

//and record a file:
NSString* recFilePath=[documentsDirectory stringByAppendingPathComponent:@"testrecordfile.wav"];
AVAudioRecording *soundrecording = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:recFilePath] settings:nil error:nil];
[soundrecording prepareToRecord];
[soundrecording record];

This is the minimum I can think of to individually play one file and record another. And this works just fine in the simulator. I can play back a file and record at the same time. But it doesn't work on the iphone itself. If I comment out either function, the other performs fine. The playback plays fine either alone or with both, if it's first. If I comment out the playback, the record records fine. (There's additional code to stop the recording not shown here.)

So each works fine, but not together. I know audioQueue has a setting to allow both, but I don't see an analogue for AVAudioSessions.

Any idea if it's possible, and if so, what I need to add?

Thanks!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c