ios - AVAudioplayer not working when app is in background -
i developing app plays recordings depending on user position. having problems when trying use app in background. have enabled background modes play audio in background , working nice in simulator. problem when autoplayrecord method called app in background doesn't play record. here code:
- (void) autoplayrecord { autoplayingrecord = [_autoplaylist objectatindex:0]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{ loadingsong = yes; dispatch_async(dispatch_get_main_queue(), ^{ [self showtitle:autoplayingrecord.title]; [audioplayer stop]; //make sure system follows our playback status [[avaudiosession sharedinstance] setcategory:avaudiosessioncategoryplayback error:nil]; [[avaudiosession sharedinstance] setactive: yes error: nil]; [[uiapplication sharedapplication] beginreceivingremotecontrolevents]; [self becomefirstresponder]; }); nserror *error; nsdata *songfile = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:autoplayingrecord.audiourl] options:nsdatareadingmappedifsafe error:&error]; audioplayer = [[avaudioplayer alloc] initwithdata:songfile error:&error]; [audioplayer setdelegate:self]; [audioplayer preparetoplay]; loadingsong = no; if (audioplayer == nil) { dispatch_async(dispatch_get_main_queue(), ^{ [activityindicatorview stopanimating]; [self stoprecord]; }); } else { dispatch_async(dispatch_get_main_queue(), ^{ [activityindicatorview stopanimating]; [audioplayer play]; }); } }); }
Comments
Post a Comment