AVAudioPlayer iOS Error

2019-09-02 01:38发布

问题:

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:

have you tried NSURL +fileURLWithPath?