我搜遍了所有Apples网站和互联网以及Stackoverflow。有没有人有任何示例代码或教程如何从内置麦克风录制音频,然后通过电子邮件导出该音频?请,我真的需要它为我的应用程序。感谢。
答案 0 :(得分:1)
我使用Apple的SpeakHere示例应用程序中的代码将内置麦克风的声音录制到wav文件“recordedFile.wav”,然后将以下方法添加到视图控制器,以将wav文件作为附件发送电子邮件:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error {
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}
- (void)mailAttachedWavFile {
MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"My Wav File"]; // optional
NSString *fileName = @"recordedFile.wav"; // whatever
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
NSData *data = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:data mimeType:@"audio/x-wav"
fileName:fileName];
NSString *emailBody = @"Wav format sound file attached."; // optional
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
您可以通过按钮将mailAttachedWavFile方法设为IBOutlet。不要忘记将控制器声明为头文件中的MFMailComposeViewControllerDelegate。