Reputation: 51
I've used MFMailComposer to send an m4a file created by AVAudioRecorder, but I can't play it back on my mac. When I download the app package through the xcode organizer, I still cannot play back the raw m4a. Does anyone have any idea how to get the m4a to play? I've tried formatting my own m4a's through core audio(using the Dirac library), but I still have the same no playing m4a problem. It seems that the AVAudioRecorder should make perfectly formatted files since it's all abstracted in there, but it seems like only AVAudioRecorder understands the format(not even itunes will read it).
Here is my mailer code:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Feedback"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
[mailer setToRecipients:toRecipients];
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"sound.m4a",
nil];
NSURL *urlfile = [NSURL fileURLWithPathComponents:pathComponents];
NSError* error = nil;
NSData* audioData = [NSData dataWithContentsOfURL:urlfile options:0 error:&error];
[mailer addAttachmentData:audioData mimeType:@"audio/mp4" fileName:@"sound.m4a"];
NSString *emailBody = @" ";
[mailer setMessageBody:emailBody isHTML:NO];
Upvotes: 0
Views: 526
Reputation: 524
Please check following:
NSData* audioData = [NSData dataWithContentsOfURL:urlfile options:0 error:&error];
if(audioData.length)
Then only add in the mail.
There might be issue in path url file.
Upvotes: 1