0

我使用 MFMailComposer 发送了一个由 AVAudioRecorder 创建的 m4a 文件,但我无法在我的 mac 上播放它。当我通过 xcode 管理器下载应用程序包时,我仍然无法播放原始 m4a。有谁知道如何让 m4a 玩?我已经尝试通过核心音频(使用 Dirac 库)格式化我自己的 m4a,但我仍然遇到同样的无法播放 m4a 问题。似乎 AVAudioRecorder 应该制作完美格式化的文件,因为它都在那里抽象,但似乎只有 AVAudioRecorder 理解格式(甚至 iTunes 都不会读取它)。

这是我的邮件代码:

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"Feedback"];

    NSArray *toRecipients = [NSArray arrayWithObjects:@"info@x.com", 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];
4

1 回答 1

1

请检查以下内容:

NSData* audioData = [NSData dataWithContentsOfURL:urlfile options:0 error:&error];

if(audioData.length)

然后只在邮件中添加。

路径 url 文件中可能存在问题。

于 2014-02-27T07:42:08.003 回答