NSOSStatusError

I am trying to play some audio in my application and it works fine up to 3 times. But when I try to play for the 4th time, it shows an error. Domain Error = NSOSStatusErrorDomain Code = -43 "Operation could not be completed (error OSStatus -43.)". The code

 NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Sun.wav", [[NSBundle mainBundle] resourcePath]]];

 NSError *error;
 AudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

 AudioPlayer.numberOfLoops = 0;

 AudioPlayer.volume=1.0;

 if (AudioPlayer == nil)
 {
    NSLog([error description]);    
 }
 else
    [AudioPlayer play];

Does anyone figure this out before ..?

+3
source share
2 answers

It looks like you are not freeing the AudioPlayer object. Thus, you can play three times, probably due to the number of open files that you can have in the AVAudioPlayer object.

view delegate methods for AVAudioPlayer: in particular

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error

you need to do something like

(in your main code)

AudioPlayer.delegate = self;

then add a function like

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
     [player release];
}

, .

+1

macerror, , OSStatus:

macerror -43

:

Mac OS error -43 (fnfErr): File not found

. , , .

+6

Source: https://habr.com/ru/post/1775126/


All Articles