IPhone : Sound does work on ipad but does NOT work on Iphone

on Saturday, April 18, 2015

I am recording audio with objective-c. I use the following code:



NSArray *dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.m4a"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];


NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:12],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:16000.0],
AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC],
AVFormatIDKey,
nil];
NSError *error = nil;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];

if (error){
Log(@"error: %@", [error localizedDescription]);
} else {
[audioRecorder prepareToRecord];
[audioRecorder record];

}


This one works perfectly on the Ipad, but does not work on the iphone. There is no error not from the code not from Xcode. The iphone has tested and working microphone and speaker. The "Do not disturb" function is turned off. The sound is on. I just do not get any sound from the speakers and it evens seems like he is recording.


Question: Why does the sound not work?


0 comments:

Post a Comment