How to handle error code -43 from NSOSStatusErrorDomain when initializing AVAudioPlayer Object?

Tanu picture Tanu · Sep 1, 2010 · Viewed 19.2k times · Source

I observed strange behavior while working with AVAudioPlayer

Following is the code:

AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",fileName]] error: &error];

In this, I downloaded the file from server and stored in application's Cache directory.

I am getting following error:

Error in playing =
Domain = NSOSStatusErrorDomain
Code = -43
Description = Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"

I also verified that file is present at that location. Everytime I restart my application, I was getting same error for song play. After some time, when I tried to run same code, my player just works fine without any error.

Can anyone tell me how to handle this error?

Also, Can anyone explain me what was the problem?

Answer

neoneye picture neoneye · May 23, 2011

AVAudioPlayer does not support streaming via HTTP. Try using AVPlayer instead.