I would like to play a sound file retrieved from my server, as a base 64 encoded file.
So far, I have decoded the file using base64 and written it to a file as so:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"voicemail.wav"]];
[fileManager createFileAtPath:filepath contents:[responseDict objectForKey:@"ResponseData"] attributes:nil];
However, I am having trouble actually playing the sound file. My code returns the error:
The operation couldn’t be completed. OSStatus error 2003334207.
Please can you tell me where I am going wrong?
NSURL * url = [NSURL fileURLWithPath:filePath];
AVAudioPlayer *sound = [[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err] autorelease];
if (! sound) {
NSLog(@"Sound had error %@", [err localizedDescription]);
} else {
[sound prepareToPlay];
[sound play];
}
@Himanshu
As suggested by the Mattias Wadman, I tried to play downloaded file using vlc/iTunes media player and the file were not playing.
So the problem may be in the encoding or in decoding of file, not in the play audio code. I checked for the same and there were some extra characters embedded while encoding.
We worked on encoding and resolved the issue.
Hope this helps.