AVAudioPlayer not playing sounds simultaneously

时光怂恿深爱的人放手 提交于 2019-12-06 11:50:27

I have faced the same while played a small file:

Here is my solution (example)

- (void)dropSoundWhileRefresh
{
    NSError *sessionError = nil;
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&sessionError];
    [[AVAudioSession sharedInstance] setActive:YES error:&sessionError];
    [[AVAudioSession sharedInstance] setDelegate:self];
    NSURL *musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"waterDrops" ofType:@"mp3"]];
    dropSound = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
    [dropSound setDelegate:self];
    [dropSound setVolume:0.10];
    [dropSound setNumberOfLoops:0];
    [dropSound play];
}

Instead of passing error as nil try this and check if initialization is working correct.

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (error) 
{
   DebugLog(@"Error in audioPlayer: %@",[error localizedDescription]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!