我想播放从我的服务器检索到的声音文件,作为 base 64 编码文件。
到目前为止,我已经使用 base64 解码了文件并将其写入文件,如下所示:
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];
但是,我在实际播放声音文件时遇到了麻烦。我的代码返回错误:
操作无法完成。OSStatus 错误 2003334207。
请你能告诉我哪里出错了吗?
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];
}