I'm making an iOS application in which I'm using AVAudioRecorder
to record outside audio and calculating power through averagePowerForChannel
function. When my app goes in background everything goes well but when I start song in iPhone music app my recording stops. Then I've used following code :
AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
Now when I play music from iPhone music app it plays without interrupting recording but plays in very low volume.
I want to record this iOS music app song as well because I'm using power somewhere in my code.
After lot of experiments finally i got to know what it needs to play song with normal volume of Music App.
AVAudioSessionCategoryOptionMixWithOthers will allow to record nearby audio. But if you want to record audio which iPhone speaker produce, you need to add this category as well AVAudioSessionCategoryOptionDefaultToSpeaker.
Below is working code:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker
error:nil];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.