播放音频且设备接听电话时,应用程序崩溃。当我挂断电话并返回应用程序时,它被阻止了。
代码:
NSURL *audioFileLocationURL;
NSString *MyAudioString;
MyAudioString = @"my-audio";
audioFileLocationURL = [[NSBundle mainBundle] URLForResource:MyAudioString withExtension:@"mp3"];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileLocationURL error:&error];
[audioPlayer setNumberOfLoops:1];
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updatemyProgress) userInfo:nil repeats:YES];
if (error) {
NSLog(@"%@", [error localizedDescription]);
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[audioPlayer prepareToPlay];
[audioPlayer setDelegate:self];
[audioPlayer play];
}