I can avoid background sound while playing new sounds. However, I cannot resume the background sound level to the maximum again. When my delegate tries to "decorate," he just holds on. The usual solution for this is AudiosessionSetProperty, but deprecated in iOS 7 and Apple does not give any hints in warnings or documentation on obsolescence.
I call this method when loading a view.
- (void) configureAVAudioSession { //get your app audioSession singleton object AVAudioSession* session = [AVAudioSession sharedInstance]; //error handling BOOL success; NSError* error; success=[session setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error]; if (!success) { NSLog(@"AVAudioSession error :%@",error); } else { } success = [session setActive:YES error:&error]; if (!success) { NSLog(@"Error setting active %@",error); } else { NSLog(@"succes settings active"); } }
This is when I play audio
-(void)playTimeOnGo { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"just-like-magic" ofType:@"mp3"]]; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; self.audioPlayer.delegate=(id<AVAudioPlayerDelegate>)self;
This is my delegate when sound is made to resume background sound and disconnect audio
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)data successfully:(BOOL)flag{ [self configureAVAudioSession]; NSLog(@"playback ended"); }
So, how do I turn off background music again without outdated APIs? call [self configureAVAudioSession]; doesn't seem to work.
deprecated background ios7 audiosession
aZtraL-EnForceR
source share