AVAudioPlayer iOS Error

2019-09-02 01:23发布

I get an error trying to play a clip using AVAudioPlayer. The error gives me:

'The operation couldn’t be completed. (OSStatus error -50.)'

I have no idea. The frameworks are all there etc...

Is it something to do with the URL?

Here's my code:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"grunt" ofType:@"aiff"];
    NSURL *fileURL = [NSURL URLWithString:soundFilePath];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
    if(!error){
        audioPlayer.delegate = self;
        [audioPlayer play];
    }else{
        NSLog(@"Error loading clip: %@", [error localizedDescription]); 
    }

Thanks in advance!

1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-02 01:49

have you tried NSURL +fileURLWithPath?

查看更多
登录 后发表回答