ios - averagePowerForChannel working with iOSimulator but don't on iPad -


in small application ios 8.0 i'm measuring microphone's input level , if it's greater -40 db i'm changing image in uiimageview , playing mp3-file. works great in iosimulator doesn't work on ipad ios 8.0. (microphone accessible app). what's issue? thanks.

//  viewcontroller.m  #import "viewcontroller.h" #import "avfoundation/avaudioplayer.h" #import <avfoundation/avfoundation.h>  @interface viewcontroller () @end  @implementation viewcontroller  nstimer *metertimer; avaudiorecorder *recorder; avaudioplayer *player; nsstring *audiofilepath; nsurl *pathasurl;   // audioplayer  - (void)viewdidload  {   [super viewdidload];  metertimer = [nstimer scheduledtimerwithtimeinterval:0.3    // sets timer interrupt target:self selector:@selector(timerarrived) userinfo:nil repeats:yes];  nsdictionary *settings = [nsdictionary dictionarywithobjectsandkeys:                           [nsnumber numberwithfloat: 44100.0],avsampleratekey,                           [nsnumber numberwithint: kaudioformatapplelossless],avformatidkey,                           [nsnumber numberwithint: 1],avnumberofchannelskey,                           [nsnumber numberwithint: avaudioqualitymax],avencoderaudioqualitykey,nil]; nserror *error; recorder = [[avaudiorecorder alloc] initwithurl:[nsurl urlwithstring:[nstemporarydirectory()             stringbyappendingpathcomponent:@"tmp.caf"]]  settings:settings error:&error]; [recorder preparetorecord]; recorder.meteringenabled = yes; [recorder record]; }  - (void)timerarrived    // called timer {   int intpower; float fvalue;     [recorder updatemeters];    // check input level     fvalue = [recorder averagepowerforchannel:0];     intpower = roundf(fvalue);     if (intpower > -40) {   _microphimage.image = [uiimage imagenamed:@"microphone2.png"];     audiofilepath = [[nsbundle mainbundle] pathforresource:@"aga" oftype:@"mp3"];     pathasurl = [[nsurl alloc] initfileurlwithpath:audiofilepath]; nserror *error;     player = [[avaudioplayer alloc] initwithcontentsofurl:pathasurl error:&error];     [player play]; } else {_microphimage.image = [uiimage imagenamed:@"microphone.png"];} }  - (void)didreceivememorywarning {[super didreceivememorywarning];}  @end 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -