如何在 Xcode 中正确创建可在 iOS 邮件中听到的音频文件
我有一个具有录制和播放功能的应用程序。这些工作正常。我还可以通过电子邮件发送音频文件。
如果我在计算机上阅读电子邮件,我可以播放音频文件。
我可以在 iDevice 上阅读电子邮件,但如果我尝试播放音频文件,我会看到类似 QT 的内容弹出一会儿,但随后该消息又返回到屏幕上。
如果我按住音频文件图标,我会得到可以使用的应用程序列表 - 但它们都是文档应用程序,而不是音频应用程序。
声音文件具有 .caf 后缀(核心音频格式)。
我的音频文件是这样创建的:
NSMutableDictionary* recordSettings = [[NSMutableDictionary alloc] init];
[recordSettings setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSettings setValue :[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];
[recordSettings setValue :[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSettings setValue :[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL settings:recordSettings error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
// ALL IS OK, START RECORDING
//NSLog(@"DetailVC - recordAudio - soundFilePath is %@", soundFile);
[audioRecorder prepareToRecord];
recordToggle = 1;
[autoCog startAnimating];
[audioRecorder record];
recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(recordingOn)
userInfo:nil
repeats:YES];
}
感谢您的任何建议。
I have an app that has record and playback capabilities. These work fine. I can also email the audio file.
If I read the email on a computer, I can play the audio file.
I can read the email on an iDevice, but if I try to play the audio file, I see something like QT pop up for a moment, but then, the message returns to the screen.
If I hold down the audiofile icon, I get a list of apps that can be used - but they are all document apps, not audio apps.
The soundfile has a .caf suffix (Core Audio Format).
My audio file is created like this:
NSMutableDictionary* recordSettings = [[NSMutableDictionary alloc] init];
[recordSettings setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSettings setValue :[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];
[recordSettings setValue :[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSettings setValue :[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL settings:recordSettings error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
// ALL IS OK, START RECORDING
//NSLog(@"DetailVC - recordAudio - soundFilePath is %@", soundFile);
[audioRecorder prepareToRecord];
recordToggle = 1;
[autoCog startAnimating];
[audioRecorder record];
recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(recordingOn)
userInfo:nil
repeats:YES];
}
Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能不在于音频创建,而在于如何将其附加到电子邮件中。您是否正确设置 MIME 类型以便邮件客户端知道如何读取数据?对于
.caf
,您应该使用audio/x-caf
MIME 类型。The problem might not be in the audio creation, but how you attach it to the email. Are you setting the MIME type correctly so the mail client knows how to read the data? For
.caf
, you should use theaudio/x-caf
MIME type.解决该问题的代码是:
The code to solve the problem was: