soleil
soleil

Reputation: 13085

AVAudioPlayer Error Domain=NSOSStatusErrorDomain Code=-43

I get the error above when trying to play a song file (chosen via MPMediaPickerController). Works fine in iOS6, but on iOS5 I get the error. Here's the code:

DLog(@"song: %@", self.customSongUrl); //always logs a valid url such as ipod-library://item/item.mp3?id=-1890948386979134309

    if (self.customSongUrl) {
        AVAudioSession *session = [AVAudioSession sharedInstance];
        [session setCategory:AVAudioSessionCategoryPlayback error:nil];

        double delayInSeconds = 1.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            NSError *error = nil;
            self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.customSongUrl error:&error];
            if (!self.audioPlayer)
            {
                NSLog(@"AVAudioPlayer could not be established: %@", error); //results in Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"                    
            }
            [self.audioPlayer prepareToPlay];
            [self.audioPlayer setNumberOfLoops:-1];
            [self.audioPlayer play];
        });
    }

From the research I've done, error -43 indicates that the file doesn't exist. But the file was chosen from the iTunes library with MPMediaPickerController. And again, this error only happens on iOS5. So why would iOS5 think the song doesn't exist?

For reference, this is how I'm getting the song url from the media picker:

- (void)mediaPicker:(MPMediaPickerController *) mediaPicker didPickMediaItems:(MPMediaItemCollection *) collection
{
    MPMediaItem *item = [[collection items] objectAtIndex:0];
    self.customSongUrl = [item valueForProperty:MPMediaItemPropertyAssetURL];

    [self dismissViewControllerAnimated:YES completion:NULL];

}

Upvotes: 1

Views: 3397

Answers (1)

Beleg
Beleg

Reputation: 362

I had a similar issue, the problem wound up being that my mp4 file target membership check box was unchecked, once I checked it, the file played perfectly.

Upvotes: 0

Related Questions