Search This Blog

Wednesday, 5 February 2014

AVAudioPlayer issue -iOS

Hello All,

Today i found a strange behaviour of AVAudioPlayer in my app, i never set any property for microphone output or anything , and also i have multiple players on different View Controllers. But on one of them the Audio Output was played through Microphone instead of Speakers.

       So here is a simple code to route audio to speakers if its coming from Microphone using AVAudioPlayer.

Simple copy and Paste this below code in your : -(void)viewDidLoad; method:

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);


Hope this helps some one someday, can save your day ;)

CHAO

Happy Programming.

No comments:

Post a Comment