NSOSStatusError
I am try to play a number of audios in my app and it is working fine upto 3 times. But when i am trying to play in 4th time it shows the error . Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)" .the code is
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Sun.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
AudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
AudioPlayer.number开发者_Go百科OfLoops = 0;
AudioPlayer.volume=1.0;
if (AudioPlayer == nil)
{
NSLog([error description]);
}
else
[AudioPlayer play];
Anybody figure it out before..?
You can use the macerror
command line utility to find out what an OSStatus code is:
macerror -43
Output:
Mac OS error -43 (fnfErr): File not found
i.e. the file you tried to use doesn't exist.
Looks like you aren't releasing the AudioPlayer object. So the fact you can play three times is probably related to the number of open files you can have in the AVAudioPlayer object.
look into the delegate methods for AVAudioPlayer: specifically
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
you'll want to do something like
(in your main code)
AudioPlayer.delegate = self;
then add function like
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[player release];
}
I'm sure you can figure out the rest.
精彩评论