NSString *songNameEscaped = [songName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *songURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", @"http://somerootpath/Music/", songNameEscaped]]; NSLog(@"songURL = %@", songURL); NSError *avPlayerError = nil; AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:songURL error:&avPlayerError]; if (avPlayerError) { NSLog(@"Error: %@", [avPlayerError description]); } else { [avPlayer play]; }
If I copy the output of NSLog from NSLog(@"songURL = %@", songURL);
and paste it into safari, Quicktime plugin plays files without problems, so I know that the URLs are valid. I tried .m4a
and .mp3
files and tried to remove spaces from songName
, but it doesn't matter that I always get Error:
Domain Error = NSOSStatusErrorDomain Code = -43 "Operation could not be completed (error OSStatus -43.)".
But these are just the standard .m4a
/ .mp3
files created in iTunes.
source share