Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudioRecorder & AVAudioPlayer with iOS 7 not working properly

Tags:

i'm having some issue with AVFoundation framework. I wrote a demo app to record audio, play it, and calculate decibels, with iOS 6. It both worked with iOS simulator built-in xcode 4.6.3 and my iPhone with iOS 6.1.3

Now i've update xcode to version 5 and tested the appa again. With the built-in simulator it works (both with iOS 6.1 and iOS 7 simulators). But when i deploy the app to my iPhone, with iOS 7.0, it doesn't work anymore.

I'm using AVAudioRecorder and AVAudioPlayer.

I don't know what could be the problem. Any suggestions? thank you!

like image 467
carlodonz Avatar asked Sep 20 '13 16:09

carlodonz


2 Answers

I was having the same issue... It appears as if Apple is now requiring the use of AVAudioSession prior to using the AVAudioRecorder. I couldn't find any documentation on this change in requirement, however the recording portion of my app is now working.

All I did was create an audioSession, set the category, and set it to be active. I did this prior to calling prepareToRecord and I tried it after the call to prepareToRecord... both ways worked.

I hope this fixes your problem!

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
like image 124
Mr.Hardy Avatar answered Sep 22 '22 08:09

Mr.Hardy


Same issue.

I have fixed it by using AVAudioSession. Moreover set properly the category of AVAudioSession:

when recording use:

[self.audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

when playing use:

[self.audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

If i don't switch the category when i play, the registration the volume is very low.

Good Luck!

like image 33
rossodisera Avatar answered Sep 21 '22 08:09

rossodisera