AVAudioPlayer iOS Error

北战南征 提交于 2020-04-21 01:11:59

问题


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?



来源:https://stackoverflow.com/questions/8158056/avaudioplayer-ios-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!