Я использую AVAudioPlayer для воспроизведения звука, но иногда громкость становится очень низкой, а не такой, как системная. Когда я изменяю громкость системы, нажимая кнопку громкости, становится нормально. Как это бывает?
код ниже:
- (void)prepareAudioSession {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
if (![session setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:&setCategoryError]) {
// handle error
}
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
BOOL result = [audioSession setActive:YES withOptions:0 error:&error];
if (!result && error) {
// deal with the error
}
}
- (void)playWithAudioPath:(NSString *)path {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
NSError *error;
NSURL *audioFileURL = [NSURL fileURLWithPath:path];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];
audioPlayer.delegate = self;
if (error == nil) {
[self prepareAudioSession];
[audioPlayer setCurrentTime:0];
[audioPlayer play];
}
else {
NSLog(@"%@", error.description);
}
});}